<!--
 * @Author: cgl
 * @Date: 2023-04-18 15:12:26
 * @LastEditors: liangkun 2669681641@qq.com
 * @LastEditTime: 2023-12-14 08:47:40
 * @FilePath: \radiation-hygiene-fe\src\views\slide\equipmentTask.vue
 * @Description:
 *
 * Copyright (c) 2023 by cgl/微盛信息产业有限公司, All Rights Reserved.
-->
<template>
  <div class="app-container">
    <el-form
      class="searchform"
      :model="queryParams"
      ref="queryParams"
      size="small"
      label-width="80px"
    >
      <el-row :gutter="20">
        <el-col :span="5">
          <el-form-item label="单位名称" label-width="80px">
            <!-- <m-select v-model="queryParams.organizationName" placeholder="输入文字检索查询" style="width: 100%" filterable clearable :lists="entrustOrganizationSelect"
              lists_label="organizationName" lists_value="organizationName" lists_key="entrustOrganizationId" :total="orgTotal" :pageSize="10"
              @handleChange="listeningEvent">
            </m-select> -->

            <el-input
              v-model="queryParams.organizationName"
              placeholder="请输入"
              @keyup.enter.native="handleSearch"
            ></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="5">
          <el-form-item label="合同编号">
            <el-input
              v-model="queryParams.agreementNumber"
              placeholder="请输入"
              clearable
              @keyup.enter.native="getList()"
            />
          </el-form-item>
        </el-col>
        <el-col :span="5">
          <el-form-item label="联系人">
            <el-input
              v-model="queryParams.contactsName"
              placeholder="请输入"
              clearable
              @keyup.enter.native="getList()"
            />
          </el-form-item>
        </el-col>
        <el-col :span="5" v-if="activeName == '2'">
          <el-form-item label="签发时间">
            <el-date-picker
              style="width: 100%"
              v-model="queryParams.signDate"
              type="daterange"
              value-format="yyyy-MM-dd"
              format="yyyy-MM-dd"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
              :unlink-panels="true"
            ></el-date-picker>
          </el-form-item>
        </el-col>
        <el-col :span="3">
          <el-form-item label-width="20px">
            <el-button
              type="primary"
              icon="el-icon-search"
              size="mini"
              @click="getList()"
              >搜索</el-button
            >
            <el-button icon="el-icon-refresh" size="mini" @click="reset()"
              >重置</el-button
            >
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>

    <div class="table-wrapper" style="position: relative">
      <div style="position: absolute; right: 20px; top: 15px; z-index: 99">
        <el-button
          type="primary"
          size="mini"
          @click.native.prevent="handleBatchDownload0"
          >批量下载报告</el-button
        >
        <el-button
          type="primary"
          size="mini"
          @click.native.prevent="handleExportSealUseRecord"
          >导出签章使用记录</el-button
        >
        <el-button
          type="primary"
          size="mini"
          @click.native.prevent="openClaimTask"
          >任务集合</el-button
        >
        <el-button
          type="primary"
          icon="el-icon-plus"
          size="mini"
          @click.native.prevent="openParticipant"
          >参与人员</el-button
        >
        <el-button
          type="primary"
          icon="el-icon-plus"
          size="mini"
          @click.native.prevent="openAuditConfig"
          >审核配置</el-button
        >
      </div>

      <el-badge
        style="position: absolute; top: 30px; left: 245px"
        :value="countData.waitMeApprovalCount || 0"
      >
        <div></div>
      </el-badge>

      <el-tabs v-model="activeName" @tab-click="changeTab" class="tab">
        <el-tab-pane
          label="待办理"
          name="-4"
          v-if="true || isPer"
        ></el-tab-pane>
        <el-tab-pane label="待检测" name="-1"></el-tab-pane>
        <el-tab-pane label="待我审批" name="4"></el-tab-pane>
        <el-tab-pane label="待审批" name="1"></el-tab-pane>
        <!-- <el-tab-pane label="已通过" name="2"></el-tab-pane> -->
        <el-tab-pane label="已签发" name="2"></el-tab-pane>
      </el-tabs>

      <el-table
        v-loading="loading"
        :data="dataList"
        :border="false"
        @row-dblclick="(row) => openhandleDialog(row, '3')"
      >
        <el-table-column label="序号" type="index" align="center" width="50">
          <template slot-scope="scope">
            <div style="text-align: center;">{{ scope.$index + 1 }}</div>
          </template>
        </el-table-column>
        <el-table-column
          label="合同编号"
          align="center"
          prop="agreementNumber"
        />
        <el-table-column
          label="委托单位"
          align="center"
          prop="organizationName"
          :show-overflow-tooltip="true"
        />
        <el-table-column
          label="联系人"
          align="center"
          prop="contactsName"
          width="120"
        />
        <el-table-column
          label="联系电话"
          align="center"
          prop="contactsMobile"
          width="150"
        />
        <el-table-column
          label="单位地址"
          align="center"
          prop="organizationAddress"
          width="150"
          :show-overflow-tooltip="true"
        />
        <el-table-column label="录入时间" align="center" prop="createTime" />
        <el-table-column
          label="签发时间"
          align="center"
          prop="tasksIssueDate"
          v-if="activeName == '2'"
        />
        <el-table-column label="驳回原因" align="center" prop="comment" />
        <!-- <el-table-column align="center" label="是否生成报告">
          <template slot-scope="{row}">
            <span v-if="row.isReport == '1'">
              已出报告
            </span>
            <span v-if="row.isReport == '0'">
              待出报告
            </span>
          </template>
        </el-table-column> -->
        <el-table-column align="center" label="操作">
          <template slot-scope="{ row }">
            <el-button
              v-if="
                activeName == '-4' || activeName == '-2' || activeName == '-1'
              "
              @click.native.prevent="openhandleDialog(row, '1')"
              type="text"
            >
              办理
            </el-button>
            <el-button
              v-if="
                (activeName == '1' || activeName == '4') && row.canAudit == '1'
              "
              @click.native.prevent="openhandleDialog(row, '2')"
              type="text"
            >
              办理
            </el-button>
            <!-- <el-button
              v-if="row.canAudit == '1' && activeName == '1'"
              @click.native.prevent="openhandleDialog(row, '2')"
              type="text">
              审核
            </el-button> -->
            <el-button
              v-if="row.tasksState == '1' || row.tasksState == '2'"
              @click.native.prevent="handleFlowRecord(row)"
              type="text"
            >
              查看流程
            </el-button>
            <el-button
              v-if="activeName == '2'"
              @click.native.prevent="handleCancelTask(row)"
              type="text"
              v-hasPermi="['task:detectionEquipment:withdraw']"
            >
              撤销
            </el-button>
          </template>
        </el-table-column>
      </el-table>

      <pagination
        v-show="total > 0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
    </div>

    <!-- 任务弹框 -->
    <el-dialog
      class="banli-task-dialog"
      :title="title"
      :visible.sync="dialogVisible"
      :close-on-click-modal="false"
      width="1600px"
      v-dialogDrag="true"
    >
      <el-form
        :model="form"
        disabled
        :rules="rules"
        ref="form"
        size="small"
        label-width="80px"
      >
        <el-row :gutter="40">
          <el-col :span="8">
            <el-form-item label="单位名称" prop="entrustOrganizationId">
              <!-- <m-select
								v-model="form.entrustOrganizationId"
								:placeholder="status != '3' ? '输入文字检索查询' : ''"
								style="width: 100%"
								filterable
								@change="changeEntrustOrganization"
								clearable
                :lists="entrustOrganizationSelect"
                lists_label="organizationName"
                lists_value="entrustOrganizationId"
                lists_key="entrustOrganizationId"
                :total="orgTotal"
                :pageSize="10"
                @handleChange="listeningEvent"
              >
							</m-select> -->
              <el-input v-model="form.organizationName" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="合同编号">
              <el-select
                v-model="form.agreementNumber"
                ref="agreement"
                @change="changeAgreement"
                placeholder=""
                style="width: 100%"
                clearable
              >
                <el-option
                  :label="item.agreementNumber"
                  :value="item.agreementNumber"
                  v-for="(item, index) in agreementList"
                  :key="index"
                >
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="联系人">
              <el-input v-model="form.contactsName" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="联系电话">
              <el-input v-model="form.contactsMobile" />
            </el-form-item>
          </el-col>
          <el-col :span="16">
            <el-form-item label="单位地址" prop="provinceCode">
              <el-input v-model="form.organizationAddress" />
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>

      <div class="btn-container">
        <el-row class="left" type="flex">
          <!-- <div class="file">
            合并报告文件:
            <div class="view">
              <span v-if="mergeReportUrl" @click="viewMergeFile()">查看</span>
            </div>
          </div> -->
          <!-- <el-upload class="docupload" ref="upload" :action="upload.url" :headers="upload.headers" :on-preview="handlePreview" :on-remove="handleRemove"
            :on-success="handleFileSuccess" :before-upload="beforeAvatarUpload" :file-list="fileList" :limit="1" accept=".docx" :on-exceed="handleExceed">
            <el-button type="primary" size="mini">上传</el-button>
          </el-upload> -->

          <div>
            <el-button type="primary" @click="handleHistoryRecord" size="mini"
              >历史记录</el-button
            >
          </div>
          <div style="margin-left: 8px">
            <el-button type="primary" @click="handleEntrustReceipt" size="mini"
              >委托书</el-button
            >
          </div>
          <div style="margin-left: 8px">
            <el-button type="primary" @click="handleBatchDownload1" size="mini"
              >批量下载报告</el-button
            >
          </div>

          <el-popover placement="bottom" trigger="click">
            <el-upload
              class="docupload"
              style="display: inline-block"
              ref="xnBigReportUpload"
              :action="upload.url"
              :headers="upload.headers"
              :on-success="
                (response, file, fileList) =>
                  handleBigReportSuccess(response, file, fileList, '10')
              "
              :limit="1"
              :show-file-list="false"
              accept=".docx"
            >
              <span class="viewfile" style="margin-left: 48px">上传</span>
            </el-upload>
            <div
              style="display: flex; align-items: center; margin-top: 5px"
              v-if="form.ossIdSnapshot"
            >
              <span>Word：</span>
              <span class="viewfile" @click="viewFile(form.ossIdSnapshot)"
                >预览</span
              >
              <span
                style="margin-left: 15px"
                class="viewfile"
                @click="dloadFile(form.ossIdSnapshot)"
                >下载</span
              >
            </div>
            <div
              style="display: flex; align-items: center; margin-top: 5px"
              v-if="form.ossId"
            >
              <span>PDF：</span>
              <span class="viewfile" @click="viewFile(form.ossId)">预览</span>
              <span
                style="margin-left: 15px"
                class="viewfile"
                @click="dloadFile(form.ossId)"
                >下载</span
              >
            </div>
            <el-button
              style="margin-left: 8px"
              slot="reference"
              type="primary"
              size="mini"
              >性能大报告</el-button
            >
          </el-popover>

          <el-popover placement="bottom" trigger="click">
            <el-upload
              class="docupload"
              style="display: inline-block"
              ref="fhBigReportUpload"
              :action="upload.url"
              :headers="upload.headers"
              :on-success="
                (response, file, fileList) =>
                  handleBigReportSuccess(response, file, fileList, '11')
              "
              :limit="1"
              :show-file-list="false"
              accept=".docx"
            >
              <span class="viewfile" style="margin-left: 48px">上传</span>
            </el-upload>
            <div
              style="display: flex; align-items: center; margin-top: 5px"
              v-if="form.protectionOssIdSnapshot"
            >
              <span>Word：</span>
              <span
                class="viewfile"
                @click="viewFile(form.protectionOssIdSnapshot)"
                >预览</span
              >
              <span
                style="margin-left: 15px"
                class="viewfile"
                @click="dloadFile(form.protectionOssIdSnapshot)"
                >下载</span
              >
            </div>
            <div
              style="display: flex; align-items: center; margin-top: 5px"
              v-if="form.protectionOssId"
            >
              <span>PDF：</span>
              <span class="viewfile" @click="viewFile(form.protectionOssId)"
                >预览</span
              >
              <span
                style="margin-left: 15px"
                class="viewfile"
                @click="dloadFile(form.protectionOssId)"
                >下载</span
              >
            </div>
            <el-button
              style="margin-left: 8px"
              slot="reference"
              type="primary"
              size="mini"
              >防护大报告</el-button
            >
          </el-popover>

          <el-popover placement="bottom" trigger="click">
            <el-upload
              class="docupload"
              style="display: inline-block"
              ref="hcBigReportUpload"
              :action="upload.url"
              :headers="upload.headers"
              :on-success="
                (response, file, fileList) =>
                  handleBigReportSuccess(response, file, fileList, '12')
              "
              :limit="1"
              :show-file-list="false"
              accept=".docx"
            >
              <span class="viewfile" style="margin-left: 48px">上传</span>
            </el-upload>
            <div
              style="display: flex; align-items: center; margin-top: 5px"
              v-if="form.checkOssIdSnapshot"
            >
              <span>Word：</span>
              <span class="viewfile" @click="viewFile(form.checkOssIdSnapshot)"
                >预览</span
              >
              <span
                style="margin-left: 15px"
                class="viewfile"
                @click="dloadFile(form.checkOssIdSnapshot)"
                >下载</span
              >
            </div>
            <div
              style="display: flex; align-items: center; margin-top: 5px"
              v-if="form.checkOssId"
            >
              <span>PDF：</span>
              <span class="viewfile" @click="viewFile(form.checkOssId)"
                >预览</span
              >
              <span
                style="margin-left: 15px"
                class="viewfile"
                @click="dloadFile(form.checkOssId)"
                >下载</span
              >
            </div>
            <el-button
              style="margin-left: 8px"
              slot="reference"
              type="primary"
              size="mini"
              >核查大报告</el-button
            >
          </el-popover>
        </el-row>

        <div class="operation">
          生成类型：
          <el-radio v-model="isPdf" label="1">pdf</el-radio>
          <el-radio v-model="isPdf" label="0">docx</el-radio>
          <div style="display: inline-block; margin-right: 15px">
            合并生成：
            <el-radio v-model="isMerge" :label="true">是</el-radio>
            <el-radio v-model="isMerge" :label="false">否</el-radio>
          </div>
          <el-button
            class="btn"
            type="primary"
            size="mini"
            @click.native.prevent="mergeReport()"
            >大报告生成</el-button
          >
          <el-button
            class="btn"
            type="primary"
            size="mini"
            @click.native.prevent="separatelyReport()"
            >批量生成</el-button
          >
          <el-button
            class="btn"
            type="primary"
            icon="el-icon-plus"
            size="mini"
            @click.native.prevent="addline()"
            v-if="status == '1'"
            >添加</el-button
          >
          <!-- <el-button
            type="primary"
            size="mini"
            @click="showTaskSubmitDialog = true;"
            >任务提交</el-button
          > -->
          <el-tooltip class="item" effect="dark" content="刷新" placement="top">
            <el-button
              size="mini"
              circle
              icon="el-icon-refresh"
              @click="refresh()"
            />
          </el-tooltip>
        </div>
      </div>

      <el-table
        :data="form.tasksContractEquipmentList"
        height="auto"
        class="handletabel"
        v-loading="handleloading"
        :row-class-name="tableRowClassName"
        :cell-class-name="tableCellClassName"
        @selection-change="handleSelectionChange"
        @row-dblclick="(row) => openDialog(row, '3')"
      >
        <el-table-column label="序号" type="index" align="center" width="50">
          <template slot-scope="scope">
            <div style="text-align: center;">{{ scope.$index + 1 }}</div>
          </template>
        </el-table-column>
          <template slot-scope="scope">
            {{ scope.$index + 1 }}
          </template>
        </el-table-column>
        <el-table-column
          label="设备名称"
          align="center"
          fixed="left"
          prop="equipmentName"
          min-width="100"
        >
          <template slot-scope="scope">
            <!-- <el-select
							@change="changeUnhandledEquipment($event, scope.row)"
							v-if="scope.row.index + ',' + scope.column.index == currentCell"
							v-model="scope.row.entrustEquipmentId"
							style="width: 100%"
							size="mini"
							:ref="`select_${scope.$index}`"
							clearable>
							<el-option
								:label="item.equipmentName"
								:value="item.entrustEquipmentId"
								v-for="(item,index) in unHandleEquipmentList"
								:key="index">
							</el-option>
						</el-select> -->

            <span>
              {{ scope.row.equipmentName }}
            </span>
          </template>
        </el-table-column>
        <el-table-column
          label="设备编号"
          align="center"
          fixed="left"
          prop="equipmentNumber"
          min-width="100"
        />
        <el-table-column
          label="规格及型号"
          align="center"
          fixed="left"
          prop="specificationModel"
          min-width="100"
          show-overflow-tooltip
        />
        <el-table-column
          label="生产厂家"
          align="center"
          prop="manufacturerName"
          min-width="120"
        />
        <el-table-column
          label="使用场所"
          align="center"
          prop="usePlace"
          min-width="120"
          show-overflow-tooltip
        />
        <el-table-column
          label="检测类别"
          align="center"
          prop="inspectionTypeId"
          min-width="160"
        >
          <template slot-scope="scope">
            <div
              v-if="
                scope.row.inspectionTypeNameList &&
                scope.row.inspectionTypeNameList.length != 0
              "
            >
              <span
                v-for="(item, index) in scope.row.inspectionTypeNameList"
                :key="index"
              >
                {{ item }}
                <span
                  v-if="
                    scope.row.inspectionTypeNameList.length != 0 &&
                    index != scope.row.inspectionTypeNameList.length - 1
                  "
                >
                  、
                </span>
              </span>
              <span v-if="scope.row.inspectionTypeId.includes('9')"
                >、环境检测</span
              >
            </div>
            <span v-if="scope.row.inspectionTypeId.includes('9')"
              >环境检测</span
            >
          </template>
        </el-table-column>
        <el-table-column
          label="检测时间"
          align="center"
          prop="detectionTime"
          min-width="120"
        />
        <el-table-column label="现场记录" align="center" min-width="190">
          <template slot-scope="scope">
            <el-popover placement="bottom" trigger="click">
              <el-button
                type="primary"
                size="mini"
                @click="viewFile(scope.row.inputOssId)"
                >预览</el-button
              >
              <el-button
                type="primary"
                size="mini"
                @click="dloadFile(scope.row.inputOssId)"
                >下载</el-button
              >
              <span
                slot="reference"
                v-show="scope.row.inputOssIdUrl"
                class="viewfile"
                >设备检测记录<br
              /></span>
            </el-popover>
            <el-popover placement="bottom" trigger="click">
              <el-button
                type="primary"
                size="mini"
                @click="viewFile(scope.row.inputOssIdSnapshot)"
                >预览</el-button
              >
              <el-button
                type="primary"
                size="mini"
                @click="dloadFile(scope.row.inputOssIdSnapshot)"
                >下载</el-button
              >
              <span
                slot="reference"
                v-show="scope.row.inputOssIdSnapshot"
                class="viewfile"
                >设备检测记录(Word)<br
              /></span>
            </el-popover>
            <el-popover placement="bottom" trigger="click">
              <el-button
                type="primary"
                size="mini"
                @click="viewFile(scope.row.protectionInputOssId)"
                >预览</el-button
              >
              <el-button
                type="primary"
                size="mini"
                @click="dloadFile(scope.row.protectionInputOssId)"
                >下载</el-button
              >
              <span
                slot="reference"
                v-show="scope.row.protectionInputOssIdUrl"
                class="viewfile"
                >防护检测记录<br
              /></span>
            </el-popover>
            <el-popover placement="bottom" trigger="click">
              <el-button
                type="primary"
                size="mini"
                @click="viewFile(scope.row.protectionInputOssIdSnapshot)"
                >预览</el-button
              >
              <el-button
                type="primary"
                size="mini"
                @click="dloadFile(scope.row.protectionInputOssIdSnapshot)"
                >下载</el-button
              >
              <span
                slot="reference"
                v-show="scope.row.protectionInputOssIdSnapshot"
                class="viewfile"
                >防护检测记录(Word)<br
              /></span>
            </el-popover>
            <span
              @click="viewFile(scope.row.cbctInputOssId)"
              v-if="scope.row.cbctInputOssIdUrl"
              class="viewfile"
              >CBCT查看</span
            >
          </template>
        </el-table-column>
        <el-table-column label="检测报告" align="center" min-width="120">
          <template slot-scope="scope">
            <el-popover placement="bottom" trigger="click">
              <el-button
                type="primary"
                size="mini"
                @click="viewFile(scope.row.ossId)"
                >预览</el-button
              >
              <el-button
                type="primary"
                size="mini"
                @click="dloadFile(scope.row.ossId)"
                >下载</el-button
              >
              <span
                slot="reference"
                v-show="scope.row.ossIdUrl"
                class="viewfile"
                >检测报告<br
              /></span>
            </el-popover>
            <el-popover placement="bottom" trigger="click">
              <el-button
                type="primary"
                size="mini"
                @click="viewFile(scope.row.protectionOssId)"
                >预览</el-button
              >
              <el-button
                type="primary"
                size="mini"
                @click="dloadFile(scope.row.protectionOssId)"
                >下载</el-button
              >
              <span
                slot="reference"
                v-show="scope.row.protectionOssIdUrl"
                class="viewfile"
                >防护报告<br
              /></span>
            </el-popover>
            <el-popover placement="bottom" trigger="click">
              <el-button
                type="primary"
                size="mini"
                @click="viewFile(scope.row.ossIdSnapshot)"
                >预览</el-button
              >
              <el-button
                type="primary"
                size="mini"
                @click="dloadFile(scope.row.ossIdSnapshot)"
                >下载</el-button
              >
              <span
                slot="reference"
                v-show="scope.row.ossIdSnapshot"
                class="viewfile"
                >检测报告(Word)<br
              /></span>
            </el-popover>
            <el-popover placement="bottom" trigger="click">
              <el-button
                type="primary"
                size="mini"
                @click="viewFile(scope.row.protectionOssIdSnapshot)"
                >预览</el-button
              >
              <el-button
                type="primary"
                size="mini"
                @click="dloadFile(scope.row.protectionOssIdSnapshot)"
                >下载</el-button
              >
              <span
                slot="reference"
                v-show="scope.row.protectionOssIdSnapshot"
                class="viewfile"
                >防护报告(Word)<br
              /></span>
            </el-popover>

            <span
              @click="viewFile(scope.row.cbctOssId)"
              v-if="scope.row.cbctOssIdUrl"
              class="viewfile"
              >CBCT查看</span
            >
          </template>
        </el-table-column>
        <el-table-column label="环境检测" align="center" min-width="120">
          <template slot-scope="scope">
            <el-popover placement="bottom" trigger="click">
              <el-button
                type="primary"
                size="mini"
                @click="viewFile(scope.row.environmentInputOssId)"
                >预览</el-button
              >
              <el-button
                type="primary"
                size="mini"
                @click="dloadFile(scope.row.environmentInputOssId)"
                >下载</el-button
              >
              <span
                slot="reference"
                v-show="scope.row.environmentInputOssIdUrl"
                class="viewfile"
                >原始记录<br
              /></span>
            </el-popover>
            <el-popover placement="bottom" trigger="click">
              <el-button
                type="primary"
                size="mini"
                @click="viewFile(scope.row.environmentReportOssId)"
                >预览</el-button
              >
              <el-button
                type="primary"
                size="mini"
                @click="dloadFile(scope.row.environmentReportOssId)"
                >下载</el-button
              >
              <span
                slot="reference"
                v-show="scope.row.environmentReportOssIdUrl"
                class="viewfile"
                >检测报告<br
              /></span>
            </el-popover>
            <el-popover placement="bottom" trigger="click">
              <el-button
                type="primary"
                size="mini"
                @click="viewFile(scope.row.environmentInputOssIdSnapshot)"
                >预览</el-button
              >
              <el-button
                type="primary"
                size="mini"
                @click="dloadFile(scope.row.environmentInputOssIdSnapshot)"
                >下载</el-button
              >
              <span
                slot="reference"
                v-show="scope.row.environmentInputOssIdSnapshotUrl"
                class="viewfile"
                >原始记录(Word)<br
              /></span>
            </el-popover>
            <el-popover placement="bottom" trigger="click">
              <el-button
                type="primary"
                size="mini"
                @click="viewFile(scope.row.environmentReportOssIdSnapshot)"
                >预览</el-button
              >
              <el-button
                type="primary"
                size="mini"
                @click="dloadFile(scope.row.environmentReportOssIdSnapshot)"
                >下载</el-button
              >
              <span
                slot="reference"
                v-show="scope.row.environmentReportOssIdSnapshotUrl"
                class="viewfile"
                >检测报告(Word)</span
              >
            </el-popover>
          </template>
        </el-table-column>
        <!-- <el-table-column label="存根" align="center" min-width="150">
          <template slot-scope="scope">
            <span @click="viewFile(scope.row.archivesOssIdUrl)" v-if="scope.row.archivesOssIdUrl" class="viewfile">查看</span>
            &nbsp;
            <span @click="viewFile(scope.row.protectionArchivesOssIdUrl)" v-if="scope.row.protectionArchivesOssIdUrl" class="viewfile">防护报告</span>
          </template>
        </el-table-column> -->
        <!-- <el-table-column label="正本" align="center" min-width="150">
          <template slot-scope="scope">
            <span @click="viewFile(scope.row.originalOssIdUrl)" v-if="scope.row.originalOssIdUrl" class="viewfile">查看</span>
            &nbsp;
            <span @click="viewFile(scope.row.protectionOriginalOssIdUrl)" v-if="scope.row.protectionOriginalOssIdUrl" class="viewfile">防护报告</span>
          </template>
        </el-table-column> -->
        <!-- <el-table-column label="回退原因" align="center" prop="backReason" show-overflow-tooltip /> -->
        <el-table-column label="初稿" align="center" min-width="115">
          <template slot-scope="scope">
            <el-upload
              class="docupload"
              style="display: inline-block"
              ref="upload"
              :action="upload.url"
              :headers="upload.headers"
              :on-success="
                (response, file, fileList) =>
                  handleChuGaoSuccess(response, file, fileList, scope.row)
              "
              :limit="1"
              :show-file-list="false"
              accept=".pdf"
            >
              <span class="viewfile">上传</span>
            </el-upload>
            &nbsp;
            <span
              v-if="scope.row.draftOssId"
              class="viewfile"
              @click="viewFile(scope.row.draftOssId)"
              >查看</span
            >
            &nbsp;
            <span
              v-if="scope.row.draftOssId"
              class="viewfile"
              style="color: red"
              @click="handleChuGaoRemove(scope.row)"
              >删除</span
            >
          </template>
        </el-table-column>
        <el-table-column label="核查记录表" align="center" min-width="90">
          <template slot-scope="scope">
            <el-popover placement="bottom" trigger="click">
              <el-button
                type="primary"
                size="mini"
                @click="viewFile(scope.row.verificationRecordOssId)"
                >预览</el-button
              >
              <el-button
                type="primary"
                size="mini"
                @click="dloadFile(scope.row.verificationRecordOssId)"
                >下载</el-button
              >
              <span
                slot="reference"
                v-show="scope.row.verificationRecordOssIdUrl"
                class="viewfile"
                >查看</span
              >
            </el-popover>
            <!-- <span @click="viewFile(scope.row.verificationRecordOssId)" v-if="scope.row.verificationRecordOssIdUrl" class="viewfile">查看</span> -->
          </template>
        </el-table-column>
        <el-table-column label="防护核查" align="center" min-width="190">
          <template slot-scope="scope">
            <el-popover placement="bottom" trigger="click">
              <el-button
                type="primary"
                size="mini"
                @click="viewFile(scope.row.protectionCheckRecordOssId)"
                >预览</el-button
              >
              <el-button
                type="primary"
                size="mini"
                @click="dloadFile(scope.row.protectionCheckRecordOssId)"
                >下载</el-button
              >
              <span
                slot="reference"
                v-show="scope.row.protectionCheckRecordOssIdUrl"
                class="viewfile"
                >原始记录<br
              /></span>
            </el-popover>
            <el-popover placement="bottom" trigger="click">
              <el-button
                type="primary"
                size="mini"
                @click="viewFile(scope.row.protectionCheckReportOssId)"
                >预览</el-button
              >
              <el-button
                type="primary"
                size="mini"
                @click="dloadFile(scope.row.protectionCheckReportOssId)"
                >下载</el-button
              >
              <span
                slot="reference"
                v-show="scope.row.protectionCheckReportOssIdUrl"
                class="viewfile"
                >核查报告<br
              /></span>
            </el-popover>
            <el-popover placement="bottom" trigger="click">
              <el-button
                type="primary"
                size="mini"
                @click="dloadFile(scope.row.protectionCheckReportSnapshot)"
                >下载</el-button
              >
              <span
                slot="reference"
                v-show="scope.row.protectionCheckReportSnapshot"
                class="viewfile"
                >核查报告(Word)</span
              >
            </el-popover>
          </template>
        </el-table-column>
        <el-table-column label="合格证" align="center" min-width="70">
          <template slot-scope="scope">
            <span
              @click="viewImg(scope.row.qualifiedCertificateOssId)"
              v-if="scope.row.qualifiedCertificateOssIdUrl"
              class="viewfile"
              >查看</span
            >
            <span
              @click="dloadFile(scope.row.qualifiedCertificateOssId)"
              v-if="scope.row.qualifiedCertificateOssIdUrl"
              class="viewfile"
              >下载</span
            >
          </template>
        </el-table-column>
        <el-table-column align="center" label="操作" fixed="right" width="200">
          <template slot-scope="scope">
            <div class="cusoperation">
              <el-button
                v-if="scope.row.entrustEquipmentId"
                @click.native.prevent="openDialog(scope.row)"
                type="text"
              >
                录入
              </el-button>
              <template v-if="status == '1' || true">
                <el-button
                  v-if="scope.row.entrustEquipmentId"
                  @click.native.prevent="generateRecordAndReport(scope.row)"
                  type="text"
                >
                  生成
                </el-button>
                <!-- <el-button v-if="scope.row.entrustEquipmentId" @click.native.prevent="generateReport(scope.row, 1)" type="text">
                  记录
                </el-button>
                <el-button v-if="scope.row.entrustEquipmentId" @click.native.prevent="generateReport(scope.row, 2)" type="text">
                  报告
                </el-button> -->
                <el-button
                  v-if="scope.row.entrustEquipmentId"
                  @click.native.prevent="deleteData(scope.row, scope.$index)"
                  type="text"
                  style="color: #f32d2d"
                >
                  删除
                </el-button>
                <div
                  v-if="scope.row.inputReportState == 2 || scope.row.state == 2"
                >
                  <el-upload
                    class="supload"
                    style="margin-right: 10px"
                    ref="upload"
                    :action="upload.url"
                    :headers="upload.headers"
                    :on-success="
                      (response) => handleFileSuccessInput(response, scope.row)
                    "
                    :before-upload="beforeAvatarUpload"
                    accept=".docx"
                    :show-file-list="false"
                  >
                    <el-button
                      type="text"
                      v-if="scope.row.inputReportState == 2"
                      >上传现场记录</el-button
                    >
                  </el-upload>
                  <el-upload
                    class="supload"
                    ref="upload"
                    :action="upload.url"
                    :headers="upload.headers"
                    :on-success="
                      (response) => handleFileSuccessTest(response, scope.row)
                    "
                    :before-upload="beforeAvatarUpload"
                    accept=".docx"
                    :show-file-list="false"
                  >
                    <el-button type="text" v-if="scope.row.state == 2"
                      >上传检测报告</el-button
                    >
                  </el-upload>
                </div>
                <el-button
                  v-if="form.taskStatus == 0 || form.ossId || !scope.row.isBack"
                  @click.native.prevent="
                    handleBackEquip(scope.row, scope.$index)
                  "
                  type="text"
                  style="color: #f32d2d"
                >
                  退回
                </el-button>

                <el-tooltip
                  effect="dark"
                  :content="scope.row.backReason"
                  placement="top"
                >
                  <div
                    style="
                      display: inline-flex;
                      margin-left: 10px;
                      cursor: pointer;
                      position: relative;
                      top: 2px;
                    "
                    v-if="scope.row.backReason"
                  >
                    <i
                      class="el-icon-warning"
                      style="font-size: 18px; color: #f32d2d"
                    ></i>
                  </div>
                </el-tooltip>
              </template>
            </div>
          </template>
        </el-table-column>
      </el-table>

      <pagination
        calss="handlepagination"
        v-show="totalHandle > 0"
        :total="totalHandle"
        :page.sync="queryParamsHandle.pageNum"
        :limit.sync="queryParamsHandle.pageSize"
        @pagination="getHandleDataList"
      />

      <div slot="footer">
        <el-button
          style="margin-right: 0px"
          type="primary"
          v-if="activeName == '-4' || activeName == '-1'"
          @click="handleOnly"
          >仅办理环境检测</el-button
        >
        <el-button
          type="primary"
          v-if="activeName == '-4' || activeName == '-1'"
          @click="handleOnlyDetection"
          >仅办理检测</el-button
        >
        <el-button type="primary" v-if="status == '1'" @click="handle(1)"
          >办 理</el-button
        >
        <el-button type="success " v-if="status == '2'" @click="handle(1)"
          >通 过</el-button
        >
        <el-button
          type="danger"
          v-if="status == '2'"
          @click="handle(2)"
          style="margin-right: 50px"
          >驳 回</el-button
        >
        <el-button @click="dialogVisible = false">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 录入弹框 -->
    <el-dialog
      :title="titleEquipment"
      :visible.sync="dialogVisibleEquipment"
      @close="handleCloseDialog"
      width="1350px"
      class="dialogVisibleEquipment"
      :destroy-on-close="true"
      v-dialogDrag="true"
    >
      <el-tabs
        class="tabEquipment"
        v-model="activeNameEquipment"
        type="card"
        @tab-click="changeTabEquipment"
        @tab-remove="removeTabEquipment"
      >
        <el-tab-pane
          v-for="(item, index) in tabList"
          :key="index"
          :label="item.label"
          :name="item.name"
          :closable="item.closable && activeNameEquipment == item.name"
        ></el-tab-pane>
      </el-tabs>

      <!-- 加载状态 -->
      <div class="loadingquery" v-if="isonblur">
        <div class="progressbox" v-if="loadingquery">
          <div class="isloading" v-loading="true"></div>
        </div>
        <div class="progressbox" v-else>
          <el-progress
            :stroke-width="2"
            :width="25"
            text-color="#13ce66"
            type="circle"
            :percentage="100"
            status="success"
          ></el-progress>
        </div>
      </div>

      <div class="content" ref="scrollref" v-if="dialogVisibleEquipment">
        <div :class="lrstatus == '3' && 'mask'">
          <itemIndex
            :key="basicForm.basicInfoCode"
            :opendialogRow="opendialogRow"
            :basicForm="basicForm"
            :tabList="tabList"
            :activeNameEquipment="activeNameEquipment"
            :lrstatus="lrstatus"
            :inspectionList="inspectionList"
            @loadingchange="loadingchange"
          ></itemIndex>
        </div>
      </div>
      <div slot="footer">
        <el-button @click="handleCloseDialog">关 闭</el-button>
      </div>
    </el-dialog>

    <!-- 添行弹框 -->
    <el-dialog
      title="添加设备"
      :visible.sync="addLineVisible"
      width="1000px"
      v-dialogDrag="true"
    >
      <el-form ref="addlinelistform" size="small">
        <el-row v-for="(parItem, parIndex) in addlineListForm" :key="parIndex">
          <el-col :span="8">
            <el-form-item
              label="设备"
              prop="entrustEquipmentId"
              label-width="90px"
            >
              <el-select
                @change="changeUnhandledEquipment($event, parIndex)"
                v-model="parItem.entrustEquipmentId"
                clearable
                style="width: 100%"
              >
                <el-option
                  :label="item.equipmentName"
                  :value="item.entrustEquipmentId"
                  v-for="(item, index) in unHandleEquipmentList"
                  :key="index"
                >
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item
              label="设备类型"
              prop="entrustEquipmentTypeCode"
              label-width="90px"
            >
              <el-select
                style="width: 100%"
                v-model="newAddEquipmentForm.entrustEquipmentTypeCode"
                placeholder="请选择"
                filterable
                clearable
              >
                <el-option
                  v-for="item in entrustEquipmentTypeSelect"
                  :key="item.equipmentTypeCode"
                  :label="item.name"
                  :value="item.equipmentTypeCode"
                >
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="指派人" prop="taskAssignor" label-width="90px">
              <el-select
                v-model="newAddEquipmentForm.taskAssignor"
                clearable
                filterable
                multiple
                style="width: 100%"
              >
                <el-option
                  :label="item.nickName"
                  :value="item.userId"
                  v-for="(item, index) in userList"
                  :key="index"
                >
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item
              class="star"
              label="检测类型"
              prop=""
              label-width="90px"
            >
              <div>
                <div class="inspect" style="margin-left: 0px">
                  <!-- 个人剂量 -->
                  <template v-if="parItem.largeCategory == '2'">
                    <el-checkbox-group
                      class="inspectcheckbox"
                      v-model="parItem.CG"
                    >
                      <el-checkbox
                        v-for="(item, index) in CGInspectList"
                        :key="index"
                        :label="item.inspectionTypeId"
                        >{{ item.typeName }}</el-checkbox
                      >
                    </el-checkbox-group>
                  </template>
                  <!-- 工业检测 -->
                  <template v-else-if="parItem.largeCategory == '3'">
                    <el-checkbox-group
                      class="inspectcheckbox"
                      v-model="parItem.FH"
                    >
                      <el-checkbox v-model="parItem.FH" disabled label="3"
                        >防护检测</el-checkbox
                      >
                    </el-checkbox-group>
                  </template>
                  <!-- 环境本底检测 -->
                  <template
                    v-else-if="
                      newAddEquipmentForm.entrustEquipmentTypeCode == '26'
                    "
                  >
                    <el-checkbox-group
                      class="inspectcheckbox"
                      v-model="parItem.FH"
                    >
                      <el-checkbox v-model="parItem.FH" disabled label="3"
                        >防护检测</el-checkbox
                      >
                    </el-checkbox-group>
                  </template>
                  <!-- 其他 -->
                  <template v-else>
                    <el-checkbox-group
                      class="inspectcheckbox"
                      v-model="parItem.FH"
                    >
                      <el-checkbox
                        v-for="(item, index) in FHInspectList"
                        :key="index"
                        :label="item.inspectionTypeId"
                        >{{ item.typeName }}</el-checkbox
                      >
                    </el-checkbox-group>
                    <el-radio-group
                      class="inspectradio"
                      v-model="parItem.radioInspecId"
                    >
                      <el-radio
                        v-for="(item, index) in radioInspectList"
                        :key="index"
                        :label="item.inspectionTypeId"
                        @click.native.prevent="
                          handleChangeRadioInspecId(
                            item.inspectionTypeId,
                            parIndex
                          )
                        "
                        >{{ item.typeName }}</el-radio
                      >
                    </el-radio-group>
                    <el-checkbox v-model="parItem.checkboxInspecId2" label="9"
                      >环境检测</el-checkbox
                    >
                    <el-form-item
                      style="margin-bottom: 0px"
                      class="star"
                      label="稳定性周期"
                      label-width="100px"
                      v-if="parItem.radioInspecId == 4"
                    >
                      <el-select
                        v-model="newAddEquipmentForm.stabilityCycle"
                        style="width: 100%"
                      >
                        <el-option
                          v-for="item in dict.type.stability_cycle"
                          :key="item.value"
                          :label="item.label"
                          :value="Number(item.value)"
                        ></el-option>
                      </el-select>
                    </el-form-item>
                  </template>
                </div>
              </div>

              <!-- <div v-else style="color: #c0c4cc; padding-left: 20px;">
                请先选择设备名称
              </div> -->
            </el-form-item>
          </el-col>
          <!-- <el-col :span="1">
            <span style="font-size: 30px; color: #2A72EE; cursor: pointer;" v-if="parIndex == 0" @click="handleOperEquipmentRow('add')">
              <i class="el-icon-circle-plus"></i>
            </span>
            <span style="font-size: 30px; color: red; cursor: pointer;" v-if="parIndex != 0" @click="handleOperEquipmentRow('del', parIndex)">
              <i class="el-icon-remove"></i>
            </span>
          </el-col> -->
        </el-row>
      </el-form>

      <el-form
        ref="newAddEquipmentFormRef"
        :model="newAddEquipmentForm"
        :rules="newAddEquipmentRules"
        size="small"
        label-width="90px"
        v-if="!addlineListForm[0].entrustEquipmentId"
      >
        <el-row>
          <el-col :span="8">
            <el-form-item label="委托单位" prop="entrustOrganizationId">
              <!-- <m-select
                v-model="newAddEquipmentForm.entrustOrganizationId"
                placeholder="请选择"
                filterable
                style="width: 100%"
                clearable
                :lists="entrustOrganizationSelect"
                lists_label="organizationName"
                lists_value="entrustOrganizationId"
                lists_key="entrustOrganizationId"
                :total="orgTotal"
                :pageSize="10"
                @handleChange="listeningEvent"
              >
              </m-select> -->
              <el-input
                v-model="newAddEquipmentForm.organizationName"
                disabled
              />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="设备名称" prop="equipmentName">
              <el-input
                v-model="newAddEquipmentForm.equipmentName"
                placeholder="请输入"
                clearable
              />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="设备类型" prop="entrustEquipmentTypeCode">
              <el-select
                v-model="newAddEquipmentForm.entrustEquipmentTypeCode"
                @change="changeEquipmentType"
                placeholder="请选择"
                style="width: 100%"
                filterable
                clearable
              >
                <el-option
                  v-for="item in entrustEquipmentTypeSelect"
                  :key="item.equipmentTypeCode"
                  :label="item.name"
                  :value="item.equipmentTypeCode"
                >
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item label="放置场所" prop="radiationSite">
              <el-input
                v-model="newAddEquipmentForm.radiationSite"
                placeholder="请输入"
                clearable
              />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="设备编号">
              <el-input
                v-model="newAddEquipmentForm.equipmentNumber"
                placeholder="请输入"
                clearable
              />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="设备型号">
              <el-input
                v-model="newAddEquipmentForm.specificationModel"
                placeholder="请输入"
                clearable
              />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="生产日期">
              <el-date-picker
                v-model="newAddEquipmentForm.purchaseTime"
                value-format="yyyy-MM-dd"
                type="date"
                style="width: 100%"
                placeholder="请选择"
              >
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="设备状况">
              <el-select
                v-model="newAddEquipmentForm.state"
                placeholder="请选择"
                style="width: 100%"
                clearable
              >
                <el-option
                  v-for="item in dict.type.equipment_state"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                >
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="生产厂家">
              <el-select
                v-model="newAddEquipmentForm.manufacturer"
                placeholder="请选择"
                filterable
                style="width: 100%"
                clearable
              >
                <el-option
                  v-for="item in manufactureSelectList"
                  :key="item.manufactureId"
                  :label="item.manufactureName"
                  :value="item.manufactureId"
                >
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item
              label="是否为车载设备"
              prop="isVehicleEquipment"
              class="line-height-1"
            >
              <el-select
                v-model="newAddEquipmentForm.isVehicleEquipment"
                placeholder="请选择"
                style="width: 100%"
              >
                <el-option
                  v-for="item in dict.type.is_or_no"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                >
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="车牌号">
              <el-input
                v-model="newAddEquipmentForm.carNum"
                placeholder="请输入"
                :disabled="newAddEquipmentForm.isVehicleEquipment == '0'"
                clearable
              />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="是否CBCT">
              <el-select
                v-model="newAddEquipmentForm.isCbct"
                placeholder="请选择"
                style="width: 100%"
              >
                <el-option
                  v-for="item in dict.type.is_or_no"
                  :key="item.value"
                  :label="item.label"
                  :value="Number(item.value)"
                >
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>

      <div style="width: 100%; text-align: center; margin: 20px 0">
        <el-button type="primary" @click="submitAddline">确 定</el-button>
        <el-button style="margin-left: 50px" @click="addLineVisible = false"
          >取 消</el-button
        >
      </div>
    </el-dialog>

    <!-- 历史记录 -->
    <history-record ref="historyRecordRefs" />
    <WorkFlow ref="workFlow"></WorkFlow>

    <!-- 添加参与人员 -->
    <participant :type="1" ref="participantRefs" />

    <!-- 审核配置弹框 -->
    <audit-config ref="auditConfigRefs"></audit-config>

    <TaskSubmitDialog
      :show.sync="showTaskSubmitDialog"
      :taskDetectionEquipmentId="openRow.taskDetectionEquipmentId"
    ></TaskSubmitDialog>

    <TaskPassDialog
      :show.sync="showTaskPassDialog"
      :row="openRow"
    ></TaskPassDialog>

    <TaskRejectDialog
      :show.sync="showTaskRejectDialog"
      :row="openRow"
    ></TaskRejectDialog>

    <WaitClaimEquipmentTaskDialog
      :show.sync="showWaitClaimEquipmentTaskDialog"
    ></WaitClaimEquipmentTaskDialog>

    <!-- 新增/修改/详情 委托协议单弹框 -->
    <AddEditEntrustReceiptDialog
      :show.sync="showAddEditEntrustReceiptDialog"
      :operType="entrustReceiptDialogOperType"
      :row="openRow"
    ></AddEditEntrustReceiptDialog>

    <!-- 导出签章使用记录 -->
    <ExportSealUseRecordDialog
      :show.sync="showExportSealUseRecordDialog"
    ></ExportSealUseRecordDialog>

    <!-- 批量下载检测报告 -->
    <BatchDownloadReportDialog
      :show.sync="showBatchDownloadReportDialog"
    ></BatchDownloadReportDialog>
  </div>
</template>

<script>
import {
  detectionEquipmentList,
  detectionEquipmentCount,
  taskAllReportOssIdByTaskId,
  detectionEquipmentDetail,
  getHandleData,
  uploadBigReportFile,
  handle,
  getUnHandleEquipmentList,
  removeResult,
  addResult,
  addBatchResult,
  addEquipmentResult,
  getResultInfo,
  updateBasicInfo,
  submit,
  generateInputReport,
  generateTestReport,
  updateInspectionType,
  mergeGenerateReport,
  separatelyGenerateReport,
  recordDetectionTime,
  uploadMergeReportFile,
  uploadInputReportFile,
  uploadTestReportFile,
  getCbctTypeCode,
  cancelTaskQuest,
  uploadChuGaoFile,
  removeChuGaoFile,
  onlyHandleEnv,
  onlyHandleDetection,
} from "@/api/testItem/detectionResult";
import { signToPdf } from "@/api/basicData/template";
import { getInspectionList } from "@/api/slides/contractTask";
import { equipmentListAll, backEquipment } from "@/api/equipment/equipment";
import { equipmentCertificateListing } from "@/api/resourse/equipmentCertificate";
import { getAgreementListWithTaskTogether } from "@/api/person/entrustAgreement";
import { getAgreementListWithTaskDosimeter } from "@/api/person/entrustAgreement";
import {
  entrustOrganizationListing,
  entrustOrganizationList,
} from "@/api/person/entrustOrganization";
import { entrustEquipmentTypeListing } from "@/api/person/entrustEquipmentType";
import itemIndex from "./components/index";
import { listOss, listByIds, delOss } from "@/api/system/oss";
import WorkFlow from "@/components/WorkFlow";
import MSelect from "@/components/mSelect";
import { getToken } from "@/utils/auth";
import { equipmentList } from "@/api/resourse/equipment";
import HistoryRecord from "./components/task/historyRecord";
import { manufactureListing } from "@/api/basicData/manufacture";
import { inspectionStandardListing } from "@/api/basicData/inspectionStandard";
import { removeDetector } from "@/api/testItem/item06";
import { removeDetector01 } from "@/api/testItem/itemTS01";
import { removeDetector03 } from "@/api/testItem/itemDSA03";
import Participant from "./components/task/participant";
import AuditConfig from "./components/task/auditConfig";
import TaskSubmitDialog from "./component/TaskSubmitDialog.vue";
import TaskPassDialog from "./component/TaskPassDialog.vue";
import TaskRejectDialog from "./component/TaskRejectDialog.vue";
import WaitClaimEquipmentTaskDialog from "./component/WaitClaimEquipmentTaskDialog.vue";
import { userListing } from "@/api/system/user";
import AddEditEntrustReceiptDialog from "@/views/entrustReceipt/components/AddEditEntrustReceiptDialog.vue";
import ExportSealUseRecordDialog from "@/views/slide/component/ExportSealUseRecord.vue";
import BatchDownloadReportDialog from "@/views/slide/component/BatchDownloadReportDialog.vue";

export default {
  name: "EquipmentTask",
  components: {
    MSelect,
    WorkFlow,
    itemIndex,
    HistoryRecord,
    Participant,
    AuditConfig,
    TaskSubmitDialog,
    TaskPassDialog,
    TaskRejectDialog,
    WaitClaimEquipmentTaskDialog,
    AddEditEntrustReceiptDialog,
    ExportSealUseRecordDialog,
    BatchDownloadReportDialog,
  },
  dicts: ["equipment_state", "is_or_no", "stability_cycle"],
  data() {
    return {
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        tasksState: "-4",
      },
      total: 0,
      dialogVisible: false,
      // 表单参数
      form: {},
      loading: false,
      status: null,
      title: null,
      rules: {
        entrustOrganizationId: [
          { required: false, message: "单位名称不能为空", trigger: "blur" },
        ],
      },
      userList: [],
      // 委托单位下拉框
      entrustOrganizationSelect: [],
      // 设备类型下拉框
      entrustEquipmentTypeSelect: [],
      // 检测类型下拉框
      inspectionList: [],
      CGInspectList: [],
      FHInspectList: [],
      radioInspectList: [],
      activeName: "-4",
      // 办理弹框
      dialogVisiblehandle: false,
      handleform: {},
      // 删除的人员
      deletePerson: [],
      // 合同下拉框
      agreementList: [],
      // 打开的当行id
      handleId: null,
      loadingHandle: false,
      btnLoading: false,
      // 添加的查询参数
      queryParamsAdd: {
        pageNum: 1,
        pageSize: 10,
      },
      totalAdd: 0,
      // 打开的当行id
      addId: null,
      loadingAdd: false,
      isPer: false,
      // 视图高度
      height: document.documentElement.clientHeight,
      dialogVisibleEquipment: false,
      activeNameEquipment: "0",
      titleEquipment: "",
      remarks: "",
      checked: [],
      equipmentType: "06",
      // 总列表
      dataList: [],
      lrstatus: null,
      // 基本信息数据
      basicForm: {},
      basicInfo: {},
      // 未办理设备列表（进行添加）
      unHandleEquipmentList: [],
      // 失焦触发请求
      isonblur: false,
      // 请求加载状态
      loadingquery: false,
      // 索引
      currentCell: null,
      // 外层打开的行
      openRow: {},
      // 办理设备的查询参数
      queryParamsHandle: {
        pageNum: 1,
        pageSize: 10,
      },
      totalHandle: 0,
      opendialogRow: {},
      equipmentTitleList: [
        {
          basicInfoCode: "01",
          title: "X射线透视设备质量控制检测现场记录",
        },
        {
          basicInfoCode: "05",
          title: "X射线摄影设备质量控制检测现场记录",
        },
        {
          basicInfoCode: "06",
          title: "数字X射线摄影设备（DR）质量控制检测现场记录",
        },
        {
          basicInfoCode: "09",
          title: "牙科X射线设备质量控制检测项目",
        },
        {
          basicInfoCode: "11",
          title: "乳腺CR设备质量控制检测现场记录",
        },
        {
          basicInfoCode: "12",
          title: "乳腺数字X射线摄影设备质量控制检测现场记录",
        },
        {
          basicInfoCode: "13",
          title: "X射线计算机体层摄影装置质量控制检测现场记录",
        },
        {
          basicInfoCode: "14",
          title: "口腔 CBCT设备性能检测原始记录",
        },
        {
          basicInfoCode: "15",
          title: "乳腺 CBCT设备性能检测原始记录",
        },
        {
          basicInfoCode: "40",
          title: "单光子发射断层成像设备（SPECT）质量控制检测现场记录",
        },
        {
          basicInfoCode: "41",
          title: "正电子发射计算机断层显像设备（PET）质量控制检测现场记录",
        },
        {
          basicInfoCode: "42",
          title: "医用磁共振成像（MRI）设备质量控制检测现场记录",
        },
        {
          basicInfoCode: "43",
          title: "螺旋断层治疗装置质量控制检测现场记录",
        },
        {
          basicInfoCode: "50",
          title: "医用电子直线加速器质量控制检测现场记录",
        },
        {
          basicInfoCode: "51",
          title: "医用电子直线加速器质量控制检测现场记录",
        },
        {
          basicInfoCode: "52",
          title: "医用X射线治疗设备质量控制检测现场记录",
        },
        {
          basicInfoCode: "53",
          title: "后装γ源近距离治疗设备质量控制检测现场记录",
        },
        {
          basicInfoCode: "54",
          title: "γ射线立体定向放射治疗系统质量控制检测现场记录",
        },
        {
          basicInfoCode: "55",
          title: "X射线立体定向放射治疗系统质量控制检测现场记录",
        },
        {
          basicInfoCode: "56",
          title: "医用γ射束远距治疗装置质量控制检测现场记录",
        },
        {
          basicInfoCode: "60",
          title: "核医学工作场所放射防护及表面污染检测现场记录",
        },
        {
          basicInfoCode: "80",
          title: "电子加速器",
        },
      ],
      testItemList: [
        {
          name: "01",
          label: "透视通用检测项目",
        },
        {
          name: "02",
          label: "直接荧光屏透视设备专用项目",
        },
        {
          name: "03",
          label: "DSA设备专用项目",
        },
        {
          name: "04",
          label: "X射线摄影设备通用检测项目",
        },
        {
          name: "05",
          label: "屏片X射线摄影设备专用检测项目",
        },
        {
          name: "06",
          label: "DR设备专用检测项目",
        },
        {
          name: "07",
          label: "CR设备专用检测项目",
        },
        {
          name: "08",
          label: "牙科X射线设备质量控制检测项目",
        },
        {
          name: "09",
          label: "乳腺摄影通用检测项目",
        },
        {
          name: "10",
          label: "乳腺屏片X射线摄影设备专用检测项目",
        },
        {
          name: "11",
          label: "乳腺DR专用检测项目",
        },
        {
          name: "12",
          label: "乳腺CR设备专用检测项目",
        },
        {
          name: "13",
          label: "X射线计算机体层摄影装置（CT）检测项目",
        },
        {
          name: "14",
          label: "口腔CBCT设备检测项目",
        },
        {
          name: "15",
          label: "乳腺CBCT设备检测项目",
        },
        {
          name: "16",
          label: "电子直线加速器中CBCT设备检测项目",
        },
        {
          name: "17",
          label: "具有CBCT功能的C形臂设备检测项目",
        },
        {
          name: "20",
          label: "检测结果",
        },
        {
          name: "21",
          label: "检测结果",
        },
        {
          name: "22",
          label: "检测结果",
        },
        {
          name: "23",
          label: "检测结果",
        },
        {
          name: "25",
          label: "环境检测结果",
        },
        {
          name: "26",
          label: "检测结果",
        },
        {
          name: "40",
          label: "设备质控检测项目",
        },
        {
          name: "41",
          label: "PET设备检测项目",
        },
        {
          name: "42",
          label: "设备质控检测项目",
        },
        {
          name: "43",
          label: "设备质控检测项目",
        },
        {
          name: "50",
          label: "检测项目和结果",
        },
        {
          name: "51",
          label: "检测项目和结果",
        },
        {
          name: "52",
          label: "检测项目和结果",
        },
        {
          name: "53",
          label: "设备质控检测项目",
        },
        {
          name: "54",
          label: "设备质控检测项目",
        },
        {
          name: "55",
          label: "设备质控检测项目",
        },
        {
          name: "56",
          label: "设备质控检测项目",
        },
        {
          name: "60",
          label: "检测结果",
        },
        {
          name: "70",
          label: "探伤机防护检测",
        },
        {
          name: "71",
          label: "密封源防护检测",
        },
        {
          name: "72",
          label: "检测结果",
        },
        {
          name: "73",
          label: "检测结果",
        },
        {
          name: "74",
          label: "检测结果",
        },
        {
          name: "80",
          label: "检测项目和结果",
        },
      ],
      // tab栏
      tabList: [],
      // 存储scrollTop
      scrollTopList: [],
      addLineVisible: false,
      addlineListForm: [
        {
          entrustEquipmentId: "",
          equipmentName: "",
          entrustEquipmentTypeCode: "",
          largeCategory: "",
          CG: [],
          FH: [],
          checkboxInspecId2: "",
          radioInspecId: null,
        },
      ],
      // 仪器
      equipmentLists: [],
      // 生成的合并报告
      mergeReportUrl: null,
      // 单位查询数据
      organizationQueryData: {
        organizationName: "", //单位名称模糊查询
        pageNum: 1, //页码
        pageSize: 10, //每页展示的条数
      },
      orgTotal: 0,
      handleloading: false,
      isPdf: "1",
      isMerge: true,
      // 用户导入参数
      upload: {
        // 是否显示弹出层（用户导入）
        open: false,
        // 弹出层标题（用户导入）
        title: "",
        // 是否禁用上传
        isUploading: false,
        // 是否更新已经存在的用户数据
        updateSupport: 0,
        // 设置上传的请求头部
        headers: {
          Authorization: "Bearer " + getToken(),
          "Content-Disposition": "inline",
        },
        // 上传的地址
        url: process.env.VUE_APP_BASE_API + "/system/oss/upload",
      },
      fileList: [],
      showNewAddEquipmentDialog: false,
      newAddEquipmentForm: {},
      newAddEquipmentRules: {
        entrustOrganizationId: [
          { required: true, message: "委托单位不能为空", trigger: "blur" },
        ],
        radiationSite: [
          { required: true, message: "放置场所不能为空", trigger: "blur" },
        ],
        equipmentName: [
          { required: true, message: "设备名称不能为空", trigger: "blur" },
        ],
        entrustEquipmentTypeCode: [
          { required: true, message: "设备类型不能为空", trigger: "blur" },
        ],
        isVehicleEquipment: [
          {
            required: true,
            message: "是否为车载设备不能为空",
            trigger: "blur",
          },
        ],
      },
      // 委托单位设备类型下拉框
      manufactureSelectList: [],
      // 检测标准下拉框
      inspectionStandardSelect: [],

      updateTimer: null,

      showTaskSubmitDialog: false,
      showTaskPassDialog: false,
      showTaskRejectDialog: false,
      showExportSealUseRecordDialog: false,
      showBatchDownloadReportDialog: false,
      showWaitClaimEquipmentTaskDialog: false,
      entrustReceiptDialogOperType: "add",
      showAddEditEntrustReceiptDialog: false,

      countData: {},
    };
  },
  provide() {
    return {
      app: this,
    };
  },
  inject: ["getAppLoading"],
  computed: {
    app_loading() {
      return this.getAppLoading();
    },
  },
  watch: {
    activeNameEquipment(newV, oldV) {},
    "newAddEquipmentForm.entrustEquipmentTypeCode"(newV, oldV) {
      if (newV == 26) {
        if (this.addlineListForm[0]) {
          this.addlineListForm[0].FH = ["3"];
        }
      }
    },
  },
  created() {
    // 首页待办跳转而来 打开办理弹窗
    if (this.$route.params.isTodo) {
      this.openhandleDialog(this.$route.params, "1");
    }
    this.getList();
    // 获取下拉框
    this.getEntrustEquipmentTypeListing();
    this.getInspectionListing();
    this.getEquipmentList();
    this.getManufactureListing();
    window.addEventListener("resize", () => {
      this.height = document.documentElement.clientHeight;
    });

    this.$on("hook:destroyed", () => {
      // console.log('clear height')
      window.removeEventListener("resize", () => {
        this.height = document.documentElement.clientHeight;
      });
    });

    // 获取检测标准下拉框
    inspectionStandardListing({}).then((response) => {
      this.inspectionStandardSelect = response.data;
    });

    this.$bus.$on("add-testItem", (code) => {
      console.log("点击了增加探测器", code);
      const findLastRes = this.tabList.findLast(
        (item) => item.name.indexOf(code) > -1
      );
      const findLastIndex = this.tabList.findLastIndex(
        (item) => item.name.indexOf(code) > -1
      );
      if (!findLastRes) return;
      let findRes = this.testItemList.find((it) => it.name == code);
      findRes = JSON.parse(JSON.stringify(findRes));
      findRes.index = findLastRes.index + 1;
      findRes.name = `copy-${findRes.index}:` + findRes.name;
      findRes.closable = true;
      this.tabList.splice(findLastIndex + 1, 0, findRes);
      console.log("标签页列表", JSON.parse(JSON.stringify(this.tabList)));
    });

    this.$bus.$on("refreshTabList", () => {
      this.openDialog(this.opendialogRow, undefined);
    });
  },
  methods: {
    handleCancelTask(row) {
      this.$modal
        .confirm(`是否撤销该任务？`)
        .then(() => {
          return cancelTaskQuest(row.taskDetectionEquipmentId);
        })
        .then(() => {
          this.$modal.msgSuccess("撤销成功");
          this.getList();
        });
    },
    // 获取设备任务列表
    getList() {
      this.loading = true;
      this.queryParams.startSignDate = this.queryParams.signDate
        ? this.queryParams.signDate[0]
        : "";
      this.queryParams.endSignDate = this.queryParams.signDate
        ? this.queryParams.signDate[1]
        : "";
      detectionEquipmentList(this.queryParams)
        .then((response) => {
          this.dataList = response.rows || [];
          this.total = response.total;
          this.loading = false;
        })
        .catch((response) => {
          this.loading = false;
        });

      this.getCount();
    },
    // 获取设备任务数量统计
    getCount() {
      detectionEquipmentCount()
        .then((res) => {
          this.countData = res.data || 0;
        })
        .catch((err) => {});
    },
    // 获取单位下拉框
    listeningEvent(e) {
      let { queryName, pageNum, pageSize, type } = e;
      if (type == "scroll" && pageNum == this.organizationQueryData.pageNum)
        return;
      this.organizationQueryData.organizationName = queryName;
      this.organizationQueryData.pageNum = pageNum;
      this.organizationQueryData.pageSize = pageSize;
      entrustOrganizationList(this.organizationQueryData).then((response) => {
        if (type == "scroll") {
          this.entrustOrganizationSelect.push(...response.rows);
        } else {
          this.entrustOrganizationSelect = response.rows;
        }
        this.orgTotal = response.total;
      });
    },
    // 获取设备类型下拉框
    getEntrustEquipmentTypeListing() {
      entrustEquipmentTypeListing().then((response) => {
        this.entrustEquipmentTypeSelect = response.data;
      });
    },
    // 获取检测类型下拉框
    getInspectionListing() {
      getInspectionList().then((response) => {
        this.inspectionList = response.rows;
        this.CGInspectList = this.inspectionList.filter((item) => {
          return item.typeName == "常规监测";
        });
        this.FHInspectList = this.inspectionList.filter((item) => {
          return item.typeName == "防护检测";
        });
        this.radioInspectList = this.inspectionList.filter((item) => {
          return item.typeName != "常规监测" && item.typeName != "防护检测";
        });
      });
    },
    // 获取用户列表
    getUserList() {
      if (this.userList.length <= 0) {
        userListing()
          .then((res) => {
            this.userList = res.data || [];
          })
          .catch((err) => {});
      }
    },
    // 历史记录
    handleHistoryRecord() {
      this.$refs.historyRecordRefs.openDialog(this.handleform);
    },
    // 委托书
    handleEntrustReceipt() {
      this.entrustReceiptDialogOperType = "add";
      this.showAddEditEntrustReceiptDialog = true;
    },
    // 批量下载报告(根据时间)
    handleBatchDownload0() {
      this.showBatchDownloadReportDialog = true;
    },
    // 批量下载报告(根据任务id)
    handleBatchDownload1() {
      taskAllReportOssIdByTaskId(this.openRow.taskDetectionEquipmentId)
        .then((res) => {
          const ossIds = res.data || [];
          if (res.data.length <= 0) {
            this.$message.error("没有可下载的报告");
            return;
          }
          listByIds(ossIds)
            .then((res2) => {
              if (!res2 || res2.data.length <= 0) {
                this.$message.error("没有可下载的报告");
                return;
              }
              res2.data.forEach((item) => {
                fetch(item.url)
                  .then((response) => response.blob())
                  .then((blob) => {
                    const url = window.URL.createObjectURL(blob);
                    const link = document.createElement("a");
                    link.href = url;
                    link.download = item.originalName;
                    document.body.appendChild(link);
                    link.click();
                    window.URL.revokeObjectURL(url);
                    link.remove();
                  });
              });
            })
            .catch((err) => {});
        })
        .catch((err) => {});
    },
    // 查看流程
    handleFlowRecord(row) {
      this.$refs.workFlow.openDialog(row);
    },
    // 打开任务对话框
    openhandleDialog(row, status) {
      this.btnLoading = true;
      this.openRow = row;
      this.form = {
        tasksContractEquipmentList: [],
      };
      this.fileList = [];
      this.isPdf = "1";
      this.isMerge = true;
      this.resetForm("form");
      this.currentCell = null;
      this.mergeReportUrl = null;
      detectionEquipmentDetail(row.taskDetectionEquipmentId).then(
        (response) => {
          this.form = response.data || {};
          if (response.data.ossId) {
            listByIds(response.data.ossId).then((response) => {
              if (response.data[0]) {
                this.mergeReportUrl = response.data[0].url;
              }
            });
          }
          if (this.form.entrustOrganizationId) {
            getAgreementListWithTaskTogether({
              entrustOrganizationId: this.form.entrustOrganizationId,
            }).then((response) => {
              this.agreementList = response.data;
            });
          }
          this.queryParamsHandle = {
            id: row.taskDetectionEquipmentId,
            pageNum: 1,
            pageSize: 10,
          };
          this.getHandleDataList();
        }
      );
      this.status = status;
      if (this.status == "1") {
        this.title = "办理设备任务";
      }
      if (this.status == "2") {
        this.title = "审核设备任务";
      }
      if (this.status == "3") {
        this.title = "查看设备任务";
      }
    },
    // 获取办理设备列表
    getHandleDataList() {
      this.handleloading = true;
      getHandleData(this.queryParamsHandle)
        .then((response) => {
          let responsedata = response.rows || [];
          this.totalHandle = response.total;
          responsedata?.forEach((item) => {
            item.inspectionTypeNameList = [];
            let arr =
              (item.inspectionTypeId && item.inspectionTypeId.split(",")) || [];
            if (arr.length != 0) {
              arr?.forEach((id) => {
                let findobj = this.inspectionList.find(
                  (item) => id == item.inspectionTypeId
                );
                if (findobj) {
                  item.inspectionTypeNameList.push(findobj.typeName);
                }
              });
            } else {
              item.CG = [];
              item.FH = [];
              item.checkboxInspecId2 = "";
              item.radioInspecId = null;
            }

            if (item.inputOssId) {
              /* 现场记录 */
              listByIds(item.inputOssId).then((response) => {
                this.$set(item, "inputOssIdUrl", response.data[0]?.url);
              });
            }
            if (item.cbctInputOssId) {
              /* 现场记录 */
              listByIds(item.cbctInputOssId).then((response) => {
                this.$set(item, "cbctInputOssIdUrl", response.data[0]?.url);
              });
            }
            if (item.protectionInputOssId) {
              /* 现场记录 */
              listByIds(item.protectionInputOssId).then((response) => {
                this.$set(
                  item,
                  "protectionInputOssIdUrl",
                  response.data[0]?.url
                );
              });
            }

            if (item.ossId) {
              /* 检测报告 */
              listByIds(item.ossId).then((response) => {
                this.$set(item, "ossIdUrl", response.data[0]?.url);
              });
            }
            if (item.cbctOssId) {
              /* 检测报告 */
              listByIds(item.cbctOssId).then((response) => {
                this.$set(item, "cbctOssIdUrl", response.data[0]?.url);
              });
            }
            if (item.protectionOssId) {
              /* 检测报告 */
              listByIds(item.protectionOssId).then((response) => {
                this.$set(item, "protectionOssIdUrl", response.data[0]?.url);
              });
            }

            if (item.environmentInputOssId) {
              /* 环境检测原始记录 */
              listByIds(item.environmentInputOssId).then((response) => {
                this.$set(
                  item,
                  "environmentInputOssIdUrl",
                  response.data[0]?.url
                );
              });
            }
            if (item.environmentReportOssId) {
              /* 环境检测报告 */
              listByIds(item.environmentReportOssId).then((response) => {
                this.$set(
                  item,
                  "environmentReportOssIdUrl",
                  response.data[0]?.url
                );
              });
            }
            if (item.environmentInputOssIdSnapshot) {
              /* 环境检测原始记录(word) */
              listByIds(item.environmentInputOssIdSnapshot).then((response) => {
                this.$set(
                  item,
                  "environmentInputOssIdSnapshotUrl",
                  response.data[0]?.url
                );
              });
            }
            if (item.environmentReportOssIdSnapshot) {
              /* 环境检测报告(word) */
              listByIds(item.environmentReportOssIdSnapshot).then(
                (response) => {
                  this.$set(
                    item,
                    "environmentReportOssIdSnapshotUrl",
                    response.data[0]?.url
                  );
                }
              );
            }

            if (item.archivesOssId) {
              /* 存根 */
              listByIds(item.archivesOssId).then((response) => {
                this.$set(item, "archivesOssIdUrl", response.data[0]?.url);
              });
            }
            if (item.protectionArchivesOssId) {
              /* 存根 */
              listByIds(item.protectionArchivesOssId).then((response) => {
                this.$set(
                  item,
                  "protectionArchivesOssIdUrl",
                  response.data[0]?.url
                );
              });
            }

            if (item.originalOssId) {
              /* 正本 */
              listByIds(item.originalOssId).then((response) => {
                this.$set(item, "originalOssIdUrl", response.data[0]?.url);
              });
            }
            if (item.protectionOriginalOssId) {
              /* 正本 */
              listByIds(item.protectionOriginalOssId).then((response) => {
                this.$set(
                  item,
                  "protectionOriginalOssIdUrl",
                  response.data[0]?.url
                );
              });
            }

            if (item.draftOssId) {
              // 初稿文件
              listByIds(item.draftOssId).then((response) => {
                this.$set(item, "draftOssIdUrl", response.data[0]?.url);
              });
            }

            if (item.verificationRecordOssId) {
              // 核查记录
              listByIds(item.verificationRecordOssId).then((response) => {
                this.$set(
                  item,
                  "verificationRecordOssIdUrl",
                  response.data[0]?.url
                );
              });
            }
            if (item.qualifiedCertificateOssId) {
              // 合格证
              listByIds(item.qualifiedCertificateOssId).then((response) => {
                this.$set(
                  item,
                  "qualifiedCertificateOssIdUrl",
                  response.data[0]?.url
                );
              });
            }

            if (item.protectionCheckRecordOssId) {
              // 防护核查报告原始记录
              listByIds(item.protectionCheckRecordOssId).then((response) => {
                this.$set(
                  item,
                  "protectionCheckRecordOssIdUrl",
                  response.data[0]?.url
                );
              });
            }
            if (item.protectionCheckReportOssId) {
              // 防护核查报告
              listByIds(item.protectionCheckReportOssId).then((response) => {
                this.$set(
                  item,
                  "protectionCheckReportOssIdUrl",
                  response.data[0]?.url
                );
              });
            }
          });
          this.$set(this.form, "tasksContractEquipmentList", responsedata);
          this.btnLoading = false;
          this.dialogVisible = true;
          this.handleloading = false;
        })
        .catch(() => {
          this.handleloading = false;
        });
    },
    // 刷新数据
    refresh() {
      detectionEquipmentDetail(this.openRow.taskDetectionEquipmentId).then(
        (response) => {
          if (response.data.ossId) {
            listByIds(response.data.ossId).then((response) => {
              if (response.data[0]) {
                this.mergeReportUrl = response.data[0].url;
              }
            });
          }
          this.form.ossId = response.data.ossId;
          this.form.ossIdSnapshot = response.data.ossIdSnapshot;
          this.form.protectionOssId = response.data.protectionOssId;
          this.form.protectionOssIdSnapshot =
            response.data.protectionOssIdSnapshot;
          this.form.checkOssId = response.data.checkOssId;
          this.form.checkOssIdSnapshot = response.data.checkOssIdSnapshot;
        }
      );
      this.getHandleDataList();
    },
    // 查询所有仪器
    async getEquipmentList() {
      let response = await equipmentListAll();
      this.equipmentLists = response.data;
    },
    // async getEquipmentList() {
    // 	let response = await equipmentList();
    // 	// equipmentList().then(response => {
    // 		this.equipmentLists = response.rows
    // 	// })
    // },
    /***
     * 根据编号查询仪器下拉框
     * type 1 普通基本信息
     * type 2 录入基本信息
     * type 3 追加基本信息
     * type 4 环境检测基本信息
     * type 5 CBCT检测基本信息
     */
    codeFilterInstrument(type = 1) {
      return new Promise(async (res, rej) => {
        let changeData;
        // let {equipmentLists} = this
        // if(!equipmentLists || equipmentLists.length==0){
        await this.getEquipmentList();
        let equipmentLists = this.equipmentLists;
        // }
        if (type === 1) {
          if (!this.basicForm.instrumentationObject) {
            return;
          }
          changeData = [...this.basicForm.instrumentationObject];
        }

        if (type === 2) {
          if (!this.basicForm.protectionDetectionVo.instrumentationObject) {
            return;
          }
          changeData = [
            ...this.basicForm.protectionDetectionVo.instrumentationObject,
          ];
        }
        if (type === 3) {
          if (!this.basicForm.appendDetectionVo.instrumentationObject) {
            return;
          }
          changeData = [
            ...this.basicForm.appendDetectionVo.instrumentationObject,
          ];
        }
        if (type === 4) {
          if (!this.basicForm.environmentDetectionVo.instrumentationObject) {
            return;
          }
          changeData = [
            ...this.basicForm.environmentDetectionVo.instrumentationObject,
          ];
        }
        if (type === 5) {
          if (!this.basicForm.cbctDetectionVo.instrumentationObject) {
            return;
          }
          changeData = [
            ...this.basicForm.cbctDetectionVo.instrumentationObject,
          ];
        }
        changeData?.forEach(async (item) => {
          let { data } = await equipmentListAll({
            instrumentTypeCode: item.code,
          });
          let hasEquipmentIndex = data?.findIndex(
            (list) => list.equipmentId == item.equipmentId
          );
          let addEquipment =
            hasEquipmentIndex > 0 || !item.equipmentId
              ? []
              : [
                  {
                    equipmentId: item.equipmentId,
                    equipmentNumber: item.equipmentNumber,
                  },
                ];
          if (hasEquipmentIndex > -1) {
            item.technicalParameter =
              data[hasEquipmentIndex].technicalParameter;
          }
          let newData = Object.assign(data, addEquipment); // addEquipment有内容的话,会覆盖data中第一条数据
          this.$set(item, "equipmentList", newData);
          // 绑定的证书列表
          if (item.certificateEntities) {
            this.$set(
              item,
              "vm_cerIdList",
              item.certificateEntities.map(
                (item) => item.equipmentCertificateId
              )
            );
          } else {
            this.$set(item, "vm_cerIdList", []);
          }
          // 证书列表下拉框
          if (item.equipmentId) {
            equipmentCertificateListing(item.equipmentId).then((response) => {
              this.$set(item, "certificateList", response.data);
            });
          } else {
            this.$set(item, "certificateList", []);
          }
        });

        if (type == 1) {
          this.$set(this.basicForm, "instrumentationObject", changeData);
        } else if (type == 2) {
          this.$set(
            this.basicForm.protectionDetectionVo,
            "instrumentationObject",
            changeData
          );
        } else if (type == 4) {
          this.$set(
            this.basicForm.environmentDetectionVo,
            "instrumentationObject",
            changeData
          );
        } else if (type == 5) {
          this.$set(
            this.basicForm.cbctDetectionVo,
            "instrumentationObject",
            changeData
          );
        }
      });
    },
    // 获取cbct检测项
    async getCbctTypeCodes() {
      let { code, data, msg } = await getCbctTypeCode(
        this.basicForm.entrustEquipmentTypeCode
      );
      if (code == 200) {
        let arr = [
          ...this.basicForm.qualityControlCodes.split(","),
          ...String(data).split(","),
        ];
        this.basicForm.qualityControlCodes = arr.join(",");
      }
    },
    // 打开录入对话框
    openDialog(row, status, tabName) {
      // 判断是否可录入
      this.lrstatus = !row.isInput ? "3" : status;
      this.opendialogRow = row;
      this.isonblur = false;
      getResultInfo(row.taskDetectionEquipmentResultId).then(
        async (response) => {
          this.basicForm = response.data || {};
          // if(!this.basicForm.basicInfoCode) {
          // 	this.$modal.msgWarning("暂无设备信息");
          // 	return;
          // }
          // 陪同人签名
          if (this.basicForm.signOssId) {
            let {
              code,
              data: signOssData,
              msg,
            } = await listByIds(this.basicForm.signOssId);
            if (code == 200) {
              this.basicForm.signOssIdUrl = signOssData[0].url;
            }
          }
          if (this.basicForm.protectionDetectionVo?.signOssId) {
            let {
              code,
              data: signOssData,
              msg,
            } = await listByIds(this.basicForm.protectionDetectionVo.signOssId);
            if (code == 200) {
              this.basicForm.protectionDetectionVo.signOssIdUrl =
                signOssData[0].url;
            }
          }
          if (this.basicForm.environmentDetectionVo?.signOssId) {
            let {
              code,
              data: signOssData,
              msg,
            } = await listByIds(
              this.basicForm.environmentDetectionVo.signOssId
            );
            if (code == 200) {
              this.basicForm.environmentDetectionVo.signOssIdUrl =
                signOssData[0].url;
            }
          }
          if (this.basicForm.cbctDetectionVo?.signOssId) {
            let {
              code,
              data: signOssData,
              msg,
            } = await listByIds(this.basicForm.cbctDetectionVo.signOssId);
            if (code == 200) {
              this.basicForm.cbctDetectionVo.signOssIdUrl = signOssData[0].url;
            }
          }

          // 检测拍照
          if (this.basicForm.sitePhotos) {
            let arr = this.basicForm?.sitePhotos?.split(",") || [];
            let photes = [];
            for (let index = 0; index < arr.length; index++) {
              const item = arr[index];
              let { code, data: siteOssData, msg } = await listByIds(item);
              photes.push(siteOssData[0].url);
            }

            this.basicForm.siteOssIdUrl = photes;
          }

          if (!this.basicForm.basicInfo) {
            this.basicForm.basicInfo = {};
          }
          if (!this.basicForm.standard) {
            this.basicForm.standard = {
              defaultStandard: [],
              otherStandard: [],
            };
          }
          if (!this.basicForm.evaluateStandard) {
            this.basicForm.evaluateStandard = {
              defaultStandard: [],
              otherStandard: [],
            };
          }

          this.$set(this.basicForm, "inspectionFHTypeIdList", []);
          if (this.basicForm.inspectionTypeId) {
            if (this.basicForm.inspectionTypeId.includes("3")) {
              this.$set(this.basicForm, "inspectionFHTypeIdList", ["3"]);
            }
            if (this.basicForm.inspectionTypeId.includes("8")) {
              this.$set(this.basicForm, "isEntrustDetection", 1);
            }
            if (this.basicForm.inspectionTypeId.includes("9")) {
            }
            const radioInspecId = this.basicForm?.inspectionTypeId?.replace(
              /,3|3,|,8|8,|,9|9,/g,
              ""
            );
            this.$set(this.basicForm, "inspectionOTTypeIdList", radioInspecId);
          }
          if (this.basicForm.protectionDetectionVo) {
            this.$set(
              this.basicForm.protectionDetectionVo,
              "inspectionFHTypeIdList",
              []
            );
            if (this.basicForm.protectionDetectionVo?.inspectionTypeId) {
              if (
                this.basicForm.protectionDetectionVo.inspectionTypeId.includes(
                  "3"
                )
              ) {
                this.$set(
                  this.basicForm.protectionDetectionVo,
                  "inspectionFHTypeIdList",
                  ["3"]
                );
              }
              if (
                this.basicForm.protectionDetectionVo.inspectionTypeId.includes(
                  "8"
                )
              ) {
                this.$set(
                  this.basicForm.protectionDetectionVo,
                  "isEntrustDetection",
                  1
                );
              }
              if (
                this.basicForm.protectionDetectionVo.inspectionTypeId.includes(
                  "9"
                )
              ) {
              }
              const radioInspecId =
                this.basicForm.protectionDetectionVo.inspectionTypeId?.replace(
                  /,3|3,|,8|8,|,9|9,/g,
                  ""
                );
              this.$set(
                this.basicForm.protectionDetectionVo,
                "inspectionOTTypeIdList",
                radioInspecId
              );
            }
          }
          if (this.basicForm.environmentDetectionVo) {
            this.$set(
              this.basicForm.environmentDetectionVo,
              "inspectionFHTypeIdList",
              []
            );
            if (this.basicForm.environmentDetectionVo?.inspectionTypeId) {
              if (
                this.basicForm.environmentDetectionVo.inspectionTypeId.includes(
                  "3"
                )
              ) {
                this.$set(
                  this.basicForm.environmentDetectionVo,
                  "inspectionFHTypeIdList",
                  ["3"]
                );
              }
              if (
                this.basicForm.environmentDetectionVo.inspectionTypeId.includes(
                  "8"
                )
              ) {
                this.$set(
                  this.basicForm.environmentDetectionVo,
                  "isEntrustDetection",
                  1
                );
              }
              if (
                this.basicForm.environmentDetectionVo.inspectionTypeId.includes(
                  "9"
                )
              ) {
              }
              const radioInspecId =
                this.basicForm.environmentDetectionVo.inspectionTypeId?.replace(
                  /,3|3,|,8|8,|,9|9,/g,
                  ""
                );
              this.$set(
                this.basicForm.environmentDetectionVo,
                "inspectionOTTypeIdList",
                radioInspecId
              );
            }
          }
          if (this.basicForm.cbctDetectionVo) {
            this.$set(
              this.basicForm.cbctDetectionVo,
              "inspectionFHTypeIdList",
              []
            );
            if (this.basicForm.cbctDetectionVo?.inspectionTypeId) {
              if (
                this.basicForm.cbctDetectionVo.inspectionTypeId.includes("3")
              ) {
                this.$set(
                  this.basicForm.cbctDetectionVo,
                  "inspectionFHTypeIdList",
                  ["3"]
                );
              }
              if (
                this.basicForm.environmentDetectionVo.inspectionTypeId.includes(
                  "8"
                )
              ) {
                this.$set(
                  this.basicForm.cbctDetectionVo,
                  "isEntrustDetection",
                  1
                );
              }
              if (
                this.basicForm.cbctDetectionVo.inspectionTypeId.includes("9")
              ) {
              }
              const radioInspecId =
                this.basicForm.cbctDetectionVo.inspectionTypeId?.replace(
                  /,3|3,|,8|8,|,9|9,/g,
                  ""
                );
              this.$set(
                this.basicForm.cbctDetectionVo,
                "inspectionOTTypeIdList",
                radioInspecId
              );
            }
          }

          if (!this.basicForm.inspectionItem) {
            this.$set(this.basicForm, "inspectionItemList", []);
          } else {
            this.$set(
              this.basicForm,
              "inspectionItemList",
              this.basicForm.inspectionItem.split(",")
            );
          }

          // 根据编号查询仪器下拉框
          this.codeFilterInstrument(1);

          let tabList = [];
          this.titleEquipment =
            this.lrstatus == "3" ? "查看设备录入" : "设备录入";
          // 录入tab
          if (row?.taskDetectionEquipmentResultId) {
            this.basicForm.resultId = row.taskDetectionEquipmentResultId;
            this.basicForm.taskResultId = row.taskDetectionEquipmentResultId;
            this.basicForm.taskDetectionEquipmentResultId =
              this.basicForm.taskDetectionEquipmentResultId ||
              row.taskDetectionEquipmentResultId;
            // 绑定的检测标准列表
            this.$set(
              this.basicForm.standard,
              "vm_otherStandardList",
              this.basicForm?.standard?.otherStandard?.map((item) => item.id) ||
                []
            );
            this.$set(
              this.basicForm.evaluateStandard,
              "vm_otherStandardList",
              this.basicForm?.evaluateStandard?.otherStandard?.map(
                (item) => item.id
              ) || []
            );
            if (this.basicForm.protectionDetectionVo) {
              this.$set(
                this.basicForm.protectionDetectionVo.standard,
                "vm_otherStandardList",
                this.basicForm?.protectionDetectionVo?.standard?.otherStandard?.map(
                  (item) => item.id
                ) || []
              );
              this.$set(
                this.basicForm.protectionDetectionVo.evaluateStandard,
                "vm_otherStandardList",
                this.basicForm?.protectionDetectionVo?.evaluateStandard?.otherStandard?.map(
                  (item) => item.id
                ) || []
              );
            }
            if (this.basicForm.environmentDetectionVo) {
              this.$set(
                this.basicForm.environmentDetectionVo.standard,
                "vm_otherStandardList",
                this.basicForm?.environmentDetectionVo?.standard?.otherStandard?.map(
                  (item) => item.id
                ) || []
              );
              this.$set(
                this.basicForm.environmentDetectionVo.evaluateStandard,
                "vm_otherStandardList",
                this.basicForm?.environmentDetectionVo?.evaluateStandard?.otherStandard?.map(
                  (item) => item.id
                ) || []
              );
            }
            if (this.basicForm.cbctDetectionVo) {
              this.$set(
                this.basicForm.cbctDetectionVo.standard,
                "vm_otherStandardList",
                this.basicForm?.cbctDetectionVo?.standard?.otherStandard?.map(
                  (item) => item.id
                ) || []
              );
              this.$set(
                this.basicForm.cbctDetectionVo.evaluateStandard,
                "vm_otherStandardList",
                this.basicForm?.cbctDetectionVo?.evaluateStandard?.otherStandard?.map(
                  (item) => item.id
                ) || []
              );
            }
            let findobj = this.equipmentTitleList.find(
              (item) => item.basicInfoCode == this.basicForm.basicInfoCode
            );
            if (findobj)
              this.titleEquipment =
                this.lrstatus == "3" ? "查看" : findobj.title;

            // 根据判断是否为CBCT添加项目
            if (this.basicForm.isCbct == 1) {
              await this.getCbctTypeCodes();
            }

            let codes = this.basicForm.qualityControlCodes?.split(",") || [];
            codes = codes.sort((a, b) => a - b);
            console.log("检测code列表", codes);
            tabList = this.basicForm.basicInfoCode
              ? [{ name: "0", label: "基本信息" }]
              : [];
            codes?.forEach((code) => {
              let findRes = this.testItemList.find((it) => it.name == code);
              if (!findRes) return;
              findRes = JSON.parse(JSON.stringify(findRes));
              const findLastRes = tabList.findLast(
                (item) => item.name.indexOf(code) > -1
              );
              if (findLastRes) {
                findRes.index = findLastRes.index + 1;
                findRes.name = `copy-${findRes.index}:` + findRes.name;
                findRes.closable = true;
              } else {
                findRes.index = 0;
              }
              tabList.push(findRes);
            });
          }
          // 防护tab
          if (this.basicForm?.protectionDetectionVo) {
            if (!this.basicForm.protectionDetectionVo.inspectionItem) {
              this.$set(
                this.basicForm.protectionDetectionVo,
                "inspectionItemList",
                []
              );
            } else {
              this.$set(
                this.basicForm.protectionDetectionVo,
                "inspectionItemList",
                this.basicForm.protectionDetectionVo.inspectionItem.split(",")
              );
            }
            this.basicForm.protectionDetectionVo.basicInfo =
              this.basicForm.protectionDetectionVo.basicInfo || {};
            this.basicForm.protectionDetectionVo.resultId =
              this.basicForm.taskDetectionEquipmentResultId;
            this.basicForm.protectionDetectionVo.taskResultId =
              this.basicForm.taskDetectionEquipmentResultId;
            let protectionDetectionVo =
              this.testItemList.find(
                (it) =>
                  it.name ==
                  this.basicForm.protectionDetectionVo.qualityControlCodes
              ) || {};
            protectionDetectionVo = JSON.parse(
              JSON.stringify(protectionDetectionVo)
            );
            tabList = [
              ...tabList,
              ...[
                { name: "index", label: "防护基本信息" },
                protectionDetectionVo,
              ],
            ];
            // 根据编号查询仪器下拉框
            this.codeFilterInstrument(2);
          }
          // 追加tab
          if (this.basicForm?.appendDetectionVo) {
            let arrApp =
              this.basicForm.appendDetectionVo?.qualityControlCodes?.split(
                ","
              ) || [];
            this.basicForm.appendDetectionVo.resultId =
              this.basicForm.taskDetectionEquipmentResultId;
            this.basicForm.appendDetectionVo.taskResultId =
              this.basicForm.taskDetectionEquipmentResultId;
            tabList.push({ label: "基本信息", name: "-1" });
            let objApp = null;
            arrApp?.forEach((item) => {
              objApp = this.testItemList.find((it) => it.name == item);
              objApp = JSON.parse(JSON.stringify(objApp));
              if (!objApp) return;
              objApp.name = "append-" + objApp.name;
              tabList.push(objApp);
            });
            this.codeFilterInstrument(3);
          }
          // 环境检测tab
          if (this.basicForm?.environmentDetectionVo) {
            if (!this.basicForm.environmentDetectionVo.inspectionItem) {
              this.$set(
                this.basicForm.environmentDetectionVo,
                "inspectionItemList",
                []
              );
            } else {
              this.$set(
                this.basicForm.environmentDetectionVo,
                "inspectionItemList",
                this.basicForm.environmentDetectionVo.inspectionItem.split(",")
              );
            }
            this.basicForm.environmentDetectionVo.basicInfo =
              this.basicForm.environmentDetectionVo.basicInfo || {};
            this.basicForm.environmentDetectionVo.resultId =
              this.basicForm.taskDetectionEquipmentResultId;
            this.basicForm.environmentDetectionVo.taskResultId =
              this.basicForm.taskDetectionEquipmentResultId;
            let environmentDetectionVo =
              this.testItemList.find(
                (it) =>
                  it.name ==
                  this.basicForm.environmentDetectionVo.qualityControlCodes
              ) || {};
            environmentDetectionVo = JSON.parse(
              JSON.stringify(environmentDetectionVo)
            );
            tabList = [
              ...tabList,
              ...[
                { name: "envir", label: "环境检测基本信息" },
                environmentDetectionVo,
              ],
            ];
            // 根据编号查询仪器下拉框
            this.codeFilterInstrument(4);
          }
          // CBCT检测tab
          if (this.basicForm?.cbctDetectionVo) {
            if (!this.basicForm.cbctDetectionVo.inspectionItem) {
              this.$set(
                this.basicForm.cbctDetectionVo,
                "inspectionItemList",
                []
              );
            } else {
              this.$set(
                this.basicForm.cbctDetectionVo,
                "inspectionItemList",
                this.basicForm.cbctDetectionVo.inspectionItem.split(",")
              );
            }
            this.basicForm.cbctDetectionVo.basicInfo =
              this.basicForm.cbctDetectionVo.basicInfo || {};
            this.basicForm.cbctDetectionVo.resultId =
              this.basicForm.taskDetectionEquipmentResultId;
            this.basicForm.cbctDetectionVo.taskResultId =
              this.basicForm.taskDetectionEquipmentResultId;
            let cbctDetectionVo =
              this.testItemList.find(
                (it) =>
                  it.name == this.basicForm.cbctDetectionVo.qualityControlCodes
              ) || {};
            cbctDetectionVo = JSON.parse(JSON.stringify(cbctDetectionVo));
            tabList = [
              ...tabList,
              ...[{ name: "cbct", label: "CBCT检测基本信息" }, cbctDetectionVo],
            ];
            // 根据编号查询仪器下拉框
            this.codeFilterInstrument(5);
          }

          // 核查记录tab
          if (
            this.basicForm?.isProtectionCheck == 1 ||
            this.basicForm?.protectionDetectionVo?.isProtectionCheck == 1 ||
            this.basicForm?.environmentDetectionVo?.isProtectionCheck == 1 ||
            this.basicForm?.cbctDetectionVo?.isProtectionCheck == 1
          ) {
            tabList.push({ label: "机房防护设施调查记录", name: "9999" });
          }

          this.basicForm = { ...this.basicForm };
          this.tabList = tabList;
          this.dialogVisibleEquipment = true;
          console.log(
            "标签页列表",
            JSON.parse(JSON.stringify(this.tabList)),
            JSON.parse(JSON.stringify(this.basicForm))
          );
          this.activeNameEquipment = tabName || this.tabList[0].name;

          this.$nextTick(() => {
            this.scrollTopList = [];
            this.$refs["scrollref"].addEventListener(
              "scroll",
              (e) => {
                let findobj = this.scrollTopList.find((item) => {
                  return item.name == this.activeNameEquipment;
                });
                if (findobj) {
                  findobj.scrollTop = this.$refs["scrollref"].scrollTop;
                } else {
                  this.scrollTopList.push({
                    name: this.activeNameEquipment,
                    scrollTop: this.$refs["scrollref"].scrollTop,
                  });
                }
              },
              true
            );
          });
        }
      );
      console.log("row", row);
      // 如果不存在检测时间则调用
      if (!row.detectionTime) {
        recordDetectionTime(row.taskDetectionEquipmentResultId);
      }
    },
    // 组件的更新请求状态
    loadingchange(val) {
      this.isonblur = true;
      this.loadingquery = val;
    },
    // 删除设备任务
    deleteData(row, index) {
      this.$modal
        .confirm(`是否确认删除该设备？`)
        .then(() => {
          return removeResult(row.taskDetectionEquipmentResultId);
        })
        .then(() => {
          this.$modal.msgSuccess("删除成功");
          this.form.tasksContractEquipmentList.splice(index, 1);
        });
    },
    handleBackEquip(row, index) {
      this.$prompt("是否确认退回该设备？", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        inputPlaceholder: "请输入退回原因",
        // inputPattern: /[\w!#$%&'*+/=?^_`{|}~-]+(?:\.[\w!#$%&'*+/=?^_`{|}~-]+)*@(?:[\w](?:[\w-]*[\w])?\.)+[\w](?:[\w-]*[\w])?/,
        //   inputErrorMessage: '邮箱格式不正确'
      })
        .then(async ({ value }) => {
          await backEquipment({
            resultId: row.taskDetectionEquipmentResultId,
            reason: value,
          });
          this.$modal.msgSuccess("退回成功");
          this.getHandleDataList();
        })
        .catch(() => {
          // this.$message({
          // 	type: 'info',
          // 	message: '取消输入'
          // });
        });
      // this.$modal
      //   .confirm(`是否确认退回该设备？`)
      //   .then(() => {
      //     return backEquipment(row.taskDetectionEquipmentResultId);
      //   })
      //   .then(() => {
      //     this.$modal.msgSuccess("删除成功");
      // 		this.form.tasksContractEquipmentList.splice(index, 1);
      //   });
    },
    // 办理1、通过1、驳回2
    handle(type) {
      if (type == 2) {
        this.showTaskRejectDialog = true;
      } else {
        if (this.form.isSignNode == 1) {
          this.showTaskPassDialog = true;
        } else {
          handle({
            id: this.openRow.taskDetectionEquipmentId,
            operation: type,
          }).then((response) => {
            this.$modal.msgSuccess("操作成功");
            this.dialogVisible = false;
          });
        }
      }
    },
    // 仅办理环境检测
    handleOnly() {
      onlyHandleEnv(this.openRow.taskDetectionEquipmentId)
        .then((res) => {
          this.$modal.msgSuccess("操作成功");
          this.dialogVisible = false;
        })
        .catch((err) => {});
    },
    // 仅办理检测
    handleOnlyDetection() {
      onlyHandleDetection(this.openRow.taskDetectionEquipmentId)
        .then((res) => {
          this.$modal.msgSuccess("操作成功");
          this.dialogVisible = false;
        })
        .catch((err) => {});
    },
    // 列表标红
    tableRowClassName({ row, rowIndex }) {
      if (row.isBack == 1) {
        return "warning-row";
      }
      return "";
    },
    // 给单元格绑定横向和竖向的index，这样就能确定是哪一个单元格
    tableCellClassName({ row, column, rowIndex, columnIndex }) {
      row.index = rowIndex;
      column.index = columnIndex;
    },
    // 添行
    addline() {
      // console.log("this.form.tasksContractEquipmentList[this.form.tasksContractEquipmentList.length - 1].entrustEquipmentId", this.form.tasksContractEquipmentList[this.form.tasksContractEquipmentList.length - 1]);
      // if(this.form.tasksContractEquipmentList.length !== 0 &&
      // 		!this.form.tasksContractEquipmentList[this.form.tasksContractEquipmentList.length - 1].entrustEquipmentId) {
      // 	this.$modal.msgWarning("有未选择的设备");
      // 	return;
      // }
      // getUnHandleEquipmentList(this.openRow.taskDetectionEquipmentId).then((response) => {
      // 	this.unHandleEquipmentList = response.data || [];
      // 	if (this.unHandleEquipmentList.length == 0) {
      // 		this.$modal.msgWarning("暂无可添加的设备");
      // 		return;
      // 	}
      // 	this.form.tasksContractEquipmentList.push(
      // 		{
      // 			CG: [],
      // 			FH: [],
      // 			radioInspecId: null,
      // 		}
      // 	);
      // 	this.currentCell = this.form.tasksContractEquipmentList.length - 1 + ',' + 1;
      // 	setTimeout(() => {
      // 		this.$refs[`select_${this.form.tasksContractEquipmentList.length - 1}`].focus();
      // 	})
      // });

      this.addlineListForm = [];
      this.addlineListForm.push({
        entrustEquipmentId: "",
        equipmentName: "",
        entrustEquipmentTypeCode: "",
        largeCategory: "",
        CG: [],
        FH: [],
        checkboxInspecId2: "",
        radioInspecId: null,
      });
      this.newAddEquipmentForm = {
        entrustEquipmentTypeCode: "",
        entrustOrganizationId: this.form.entrustOrganizationId,
        organizationName: this.form.organizationName,
        isVehicleEquipment: "0",
        state: "0",
        taskAssignor: [],
        stabilityCycle: "",
      };
      getUnHandleEquipmentList(this.openRow.taskDetectionEquipmentId).then(
        (response) => {
          this.unHandleEquipmentList = response.data || [];
          // if (this.unHandleEquipmentList.length == 0) {
          //   this.$modal.msgWarning("暂无可添加的设备");
          //   return;
          // }
          this.addLineVisible = true;
          this.resetForm("addlinelistform");
        }
      );

      this.getUserList();
    },
    // 更改设备类型
    changeEquipmentType(val) {
      let findobj = this.entrustEquipmentTypeSelect.find(
        (item) => item.equipmentTypeCode == val
      );
      if (!findobj) return;
      this.newAddEquipmentForm.basicInfoCode = findobj.basicInfoCode;
      this.newAddEquipmentForm.equipmentName = findobj.name;
    },
    // 获取生产厂家下拉框
    getManufactureListing() {
      manufactureListing().then((response) => {
        this.manufactureSelectList = response.data;
      });
    },
    // 更改未办理设备
    changeUnhandledEquipment(val, index) {
      const findRes = this.unHandleEquipmentList.find(
        (item) => item.entrustEquipmentId == val
      );
      this.addlineListForm[index].CG = [];
      this.addlineListForm[index].FH = [];
      if (findRes?.largeCategory == "3") {
        this.addlineListForm[index].FH = ["3"];
      }
      this.addlineListForm[index].checkboxInspecId2 = "";
      this.addlineListForm[index].radioInspecId = [];
      this.addlineListForm[index].equipmentName = findRes?.equipmentName || "";
      this.addlineListForm[index].largeCategory = findRes?.largeCategory || "";
      this.newAddEquipmentForm.entrustEquipmentTypeCode =
        findRes?.entrustEquipmentTypeCode || "";
    },
    handleOperEquipmentRow(type, index) {
      if (type == "add") {
        this.addlineListForm.push({
          entrustEquipmentId: "",
          equipmentName: "",
          entrustEquipmentTypeCode: "",
          largeCategory: "",
          CG: [],
          FH: [],
          checkboxInspecId2: "",
          radioInspecId: null,
        });
      } else if (type == "del") {
        this.addlineListForm.splice(index, 1);
      }
    },
    // 添加设备
    async submitAddline() {
      let valid = true;
      for (let i = 0; i < this.addlineListForm.length; i++) {
        const item = this.addlineListForm[i];

        // if (!item.entrustEquipmentId) {
        //   this.$modal.msgWarning("设备名称不能为空");
        //   valid = false
        //   break;
        // }

        if (
          item.CG.length == 0 &&
          item.FH.length == 0 &&
          (!item.radioInspecId || item.radioInspecId.length == 0) &&
          !item.checkboxInspecId2
        ) {
          this.$modal.msgWarning("检测类型不能为空");
          valid = false;
          break;
        }
      }
      if (!valid) return;

      const dataList = [];
      for (let i = 0; i < this.addlineListForm.length; i++) {
        const item = this.addlineListForm[i];
        let arr = [];
        if (item.CG.length != 0) {
          arr.push(...item.CG);
        }
        if (item.FH.length != 0) {
          arr.push(...item.FH);
        }
        if (item.radioInspecId) {
          arr.push(item.radioInspecId);
        }
        if (item.checkboxInspecId2) {
          arr.push("9");
        }
        dataList.push({
          id: this.openRow.taskDetectionEquipmentId,
          equipmentId: item.entrustEquipmentId,
          entrustEquipmentTypeCode: item.entrustEquipmentTypeCode,
          instrumentTypeId: arr.join(","),
        });
      }
      const uniqueIds = dataList
        .map((item) => item.equipmentId)
        .filter((id, index, self) => self.indexOf(id) === index);
      if (uniqueIds.length !== dataList.length) {
        this.$modal.msgError("不可添加相同设备");
        return;
      }
      // console.log(dataList)

      let valid2 = true;
      if (!this.$refs.newAddEquipmentFormRef) valid2 = true;
      else
        valid2 = await this.$refs.newAddEquipmentFormRef
          .validate()
          .catch((err) => {});
      if (!valid2) return;

      const data = {
        id: this.openRow.taskDetectionEquipmentId,
        instrumentTypeId: dataList[0].instrumentTypeId,
        entrustEquipment: JSON.parse(JSON.stringify(this.newAddEquipmentForm)),
      };
      data.entrustEquipment.equipmentId = dataList[0].equipmentId;
      // console.log(data)

      data.entrustEquipmentTypeCode = this.newAddEquipmentForm.entrustEquipmentTypeCode;
      data.taskAssignor = this.newAddEquipmentForm.taskAssignor?.join(",");
      addEquipmentResult(data).then((response) => {
        this.$modal.msgSuccess("添加成功");
        this.getHandleDataList();
        this.addLineVisible = false;
      });
    },
    // 更改委托单位下拉
    changeEntrustOrganization(val) {
      let obj = this.entrustOrganizationSelect.find((item) => {
        return item.entrustOrganizationId == val;
      });
      if (!obj) {
        this.form.contactsName = null;
        this.form.organizationAddress = null;
        this.form.contactsMobile = null;
        this.form.agreementNumber = null;
        this.agreementList = [];
        return;
      }
      this.form.contactsName = obj.contactsName;
      this.form.organizationAddress = obj.addressDetails;
      this.form.contactsMobile = obj.contactsMobile;
      this.$set(this.form, "agreementId", null);
      this.$set(this.form, "agreementNumber", null);
    },
    // 更改合同下拉
    changeAgreement(val) {
      let obj = this.agreementList.find((item) => {
        return item.agreementNumber == val;
      });
      if (obj) {
        this.$set(this.form, "agreementId", obj.agreementId);
      }
    },
    // 切换tab栏
    changeTab(tab) {
      this.queryParams.tasksState = tab.name;
      this.dataList = [];
      this.getList();
    },
    // 切换弹框tab栏
    changeTabEquipment(tab) {
      this.$nextTick(() => {
        window.MathJax.Hub.Queue([
          "Typeset",
          window.MathJax.Hub,
          document.getElementsByTagName("i"),
        ]);
        let findobj = this.scrollTopList.find((item) => {
          return item.name == tab.name;
        });
        if (findobj) {
          this.$refs["scrollref"].scrollTop = findobj.scrollTop;
        } else {
          this.$refs["scrollref"].scrollTop = 0;
        }
        this.isonblur = false;

        if (
          this.activeNameEquipment == "0" ||
          this.activeNameEquipment == "index" ||
          this.activeNameEquipment == "envir" ||
          this.activeNameEquipment == "cbct"
        ) {
          getResultInfo(this.opendialogRow.taskDetectionEquipmentResultId).then(
            async (response) => {
              if (this.activeNameEquipment == "index") {
                this.basicForm.protectionDetectionVo.equipmentName =
                  response.data?.protectionDetectionVo?.equipmentName || "";
                this.basicForm.protectionDetectionVo.specificationModel =
                  response.data?.protectionDetectionVo?.specificationModel ||
                  "";
                this.basicForm.protectionDetectionVo.equipmentNumber =
                  response.data?.protectionDetectionVo?.equipmentNumber || "";
                this.basicForm.protectionDetectionVo.manufacturerName =
                  response.data?.protectionDetectionVo?.manufacturerName || "";
                this.basicForm.protectionDetectionVo.usePlace =
                  response.data?.protectionDetectionVo?.usePlace || "";
                this.basicForm.protectionDetectionVo.detectionTime =
                  response.data?.protectionDetectionVo?.detectionTime || "";
                this.basicForm.protectionDetectionVo.agreementNumber =
                  response.data?.protectionDetectionVo?.agreementNumber || "";
                this.basicForm.protectionDetectionVo.reportNumber =
                  response.data?.protectionDetectionVo?.reportNumber || "";
                this.basicForm.protectionDetectionVo.entrustOrganizationAddress =
                  response.data?.protectionDetectionVo
                    ?.entrustOrganizationAddress || "";
                this.basicForm.protectionDetectionVo.entrustOrganizationName =
                  response.data?.protectionDetectionVo
                    ?.entrustOrganizationName || "";
                this.basicForm.protectionDetectionVo.instrumentationObject =
                  response.data?.protectionDetectionVo?.instrumentationObject ||
                  "";
                this.codeFilterInstrument(2);
              }
              if (this.activeNameEquipment == "envir") {
                this.basicForm.environmentDetectionVo.equipmentName =
                  response.data?.environmentDetectionVo?.equipmentName || "";
                this.basicForm.environmentDetectionVo.specificationModel =
                  response.data?.environmentDetectionVo?.specificationModel ||
                  "";
                this.basicForm.environmentDetectionVo.equipmentNumber =
                  response.data?.environmentDetectionVo?.equipmentNumber || "";
                this.basicForm.environmentDetectionVo.manufacturerName =
                  response.data?.environmentDetectionVo?.manufacturerName || "";
                this.basicForm.environmentDetectionVo.usePlace =
                  response.data?.environmentDetectionVo?.usePlace || "";
                this.basicForm.environmentDetectionVo.detectionTime =
                  response.data?.environmentDetectionVo?.detectionTime || "";
                this.basicForm.environmentDetectionVo.agreementNumber =
                  response.data?.environmentDetectionVo?.agreementNumber || "";
                this.basicForm.environmentDetectionVo.reportNumber =
                  response.data?.environmentDetectionVo?.reportNumber || "";
                this.basicForm.environmentDetectionVo.entrustOrganizationAddress =
                  response.data?.environmentDetectionVo
                    ?.entrustOrganizationAddress || "";
                this.basicForm.environmentDetectionVo.entrustOrganizationName =
                  response.data?.environmentDetectionVo
                    ?.entrustOrganizationName || "";
                this.basicForm.environmentDetectionVo.instrumentationObject =
                  response.data?.environmentDetectionVo
                    ?.instrumentationObject || "";
                this.codeFilterInstrument(4);
              }
              if (this.activeNameEquipment == "cbct") {
                this.basicForm.cbctDetectionVo.equipmentName =
                  response.data?.cbctDetectionVo?.equipmentName || "";
                this.basicForm.cbctDetectionVo.specificationModel =
                  response.data?.cbctDetectionVo?.specificationModel || "";
                this.basicForm.cbctDetectionVo.equipmentNumber =
                  response.data?.cbctDetectionVo?.equipmentNumber || "";
                this.basicForm.cbctDetectionVo.manufacturerName =
                  response.data?.cbctDetectionVo?.manufacturerName || "";
                this.basicForm.cbctDetectionVo.usePlace =
                  response.data?.cbctDetectionVo?.usePlace || "";
                this.basicForm.cbctDetectionVo.detectionTime =
                  response.data?.cbctDetectionVo?.detectionTime || "";
                this.basicForm.cbctDetectionVo.agreementNumber =
                  response.data?.cbctDetectionVo?.agreementNumber || "";
                this.basicForm.cbctDetectionVo.reportNumber =
                  response.data?.cbctDetectionVo?.reportNumber || "";
                this.basicForm.cbctDetectionVo.entrustOrganizationAddress =
                  response.data?.cbctDetectionVo?.entrustOrganizationAddress ||
                  "";
                this.basicForm.cbctDetectionVo.entrustOrganizationName =
                  response.data?.cbctDetectionVo?.entrustOrganizationName || "";
                this.basicForm.cbctDetectionVo.instrumentationObject =
                  response.data?.cbctDetectionVo?.instrumentationObject || "";
                this.codeFilterInstrument(5);
              }
              if (this.activeNameEquipment == "0") {
                this.basicForm.equipmentName =
                  response.data?.equipmentName || "";
                this.basicForm.specificationModel =
                  response.data?.specificationModel || "";
                this.basicForm.equipmentNumber =
                  response.data?.equipmentNumber || "";
                this.basicForm.manufacturerName =
                  response.data?.manufacturerName || "";
                this.basicForm.usePlace = response.data?.usePlace || "";
                this.basicForm.detectionTime =
                  response.data?.detectionTime || "";
                this.basicForm.agreementNumber =
                  response.data?.agreementNumber || "";
                this.basicForm.reportNumber = response.data?.reportNumber || "";
                this.basicForm.entrustOrganizationAddress =
                  response.data?.entrustOrganizationAddress || "";
                this.basicForm.entrustOrganizationName =
                  response.data?.entrustOrganizationName || "";
              }
            }
          );
        }
      });
    },
    // 移除弹框tab栏
    removeTabEquipment(name) {
      const findItem = this.tabList.find((item) => item.name == name);
      // DR专用检测项
      if (name.indexOf("06") > -1) {
        removeDetector(this.basicForm.resultId, findItem.index)
          .then((res) => {
            const findIndex = this.tabList.findIndex(
              (item) => item.name == name
            );
            this.tabList.splice(findIndex, 1);
            for (let i = findIndex; i < this.tabList.length; i++) {
              if (this.tabList[i].name.indexOf("06") > -1) {
                this.tabList[i].index = this.tabList[i].index - 1;
                this.tabList[i].name = `copy-${this.tabList[i].index}:06`;
              }
            }
            if (this.activeNameEquipment == name) {
              if (findIndex > 0) {
                this.activeNameEquipment = this.tabList[findIndex - 1].name;
              } else {
                this.activeNameEquipment = this.tabList[findIndex].name;
              }
            }
            console.log("标签页列表", JSON.parse(JSON.stringify(this.tabList)));
          })
          .catch((err) => {});
      }
      // 透视通用检测项目
      else if (name.indexOf("01") > -1) {
        removeDetector01(this.basicForm.resultId, findItem.index)
          .then((res) => {
            const findIndex = this.tabList.findIndex(
              (item) => item.name == name
            );
            this.tabList.splice(findIndex, 1);
            for (let i = findIndex; i < this.tabList.length; i++) {
              if (this.tabList[i].name.indexOf("01") > -1) {
                this.tabList[i].index = this.tabList[i].index - 1;
                this.tabList[i].name = `copy-${this.tabList[i].index}:01`;
              }
            }
            if (this.activeNameEquipment == name) {
              if (findIndex > 0) {
                this.activeNameEquipment = this.tabList[findIndex - 1].name;
              } else {
                this.activeNameEquipment = this.tabList[findIndex].name;
              }
            }
            console.log("标签页列表", JSON.parse(JSON.stringify(this.tabList)));
          })
          .catch((err) => {});
      }
      // DAS专用检测项目
      else if (name.indexOf("03") > -1) {
        removeDetector03(this.basicForm.resultId, findItem.index)
          .then((res) => {
            const findIndex = this.tabList.findIndex(
              (item) => item.name == name
            );
            this.tabList.splice(findIndex, 1);
            for (let i = findIndex; i < this.tabList.length; i++) {
              if (this.tabList[i].name.indexOf("03") > -1) {
                this.tabList[i].index = this.tabList[i].index - 1;
                this.tabList[i].name = `copy-${this.tabList[i].index}:03`;
              }
            }
            if (this.activeNameEquipment == name) {
              if (findIndex > 0) {
                this.activeNameEquipment = this.tabList[findIndex - 1].name;
              } else {
                this.activeNameEquipment = this.tabList[findIndex].name;
              }
            }
            console.log("标签页列表", JSON.parse(JSON.stringify(this.tabList)));
          })
          .catch((err) => {});
      }
    },
    // 提交任务
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (!valid) return;
        let deleteIds = this.deletePerson.map((item) => {
          return {
            id: item.taskPersonalResultId,
            dosageType: item.dosageType,
          };
        });
        if (this.status == "1") {
          let form = {
            entrustOrganizationId: this.form.entrustOrganizationId,
            agreementId: this.form.agreementId,
            wearingBeginTime: this.form.wearingBeginTime,
            wearingEndTime: this.form.wearingEndTime,
            deleteItems: deleteIds,
          };
          personalDosimeterAdd(form).then((response) => {
            this.$modal.msgSuccess("新增成功");
            this.dialogVisible = false;
            this.getList();
          });
        }
      });
    },
    // 分页获取人员（添加时根据单位id）
    getListAdd() {
      this.queryParamsAdd.entrustOrganizationId = this.addId;
      this.loadingAdd = true;
      getWorkingPersonnelByOrganizationId(this.queryParamsAdd)
        .then((response) => {
          this.form.taskPersonalDosimeterResultList = response.rows;
          if (this.form.taskPersonalDosimeterResultList.length != 0) {
            let obj = this.form.taskPersonalDosimeterResultList[0];
            if (obj.wearingBeginTime) {
              this.$set(this.form, "wearingBeginTime", obj.wearingBeginTime);
            }
            if (obj.wearingEndTime) {
              this.$set(this.form, "wearingEndTime", obj.wearingEndTime);
            }
          }
          this.totalAdd = response.total;
          this.loadingAdd = false;
        })
        .catch((response) => {
          this.loadingAdd = false;
        });
    },
    // 提交办理/保存
    launch(type) {
      let form = {
        id: this.handleform.taskPersonalDosimeterId,
        wearingBeginTime: this.handleform.wearingBeginTime,
        wearingEndTime: this.handleform.wearingEndTime,
        agreementId: this.handleform.agreementId,
        operation: type,
        operationList: this.handleform.operationList,
      };
      personalDosimeterHandle(form).then((response) => {
        this.$modal.msgSuccess("操作成功");
        this.dialogVisiblehandle = false;
        this.getList();
      });
    },
    // 更改单位（添加时）
    changeEntrustOrganizationId(val) {
      this.addId = val;
      let obj = this.entrustOrganizationSelect.find((item) => {
        return item.entrustOrganizationId == val;
      });
      if (!obj) {
        this.form = {
          taskPersonalDosimeterResultList: [],
        };
        this.agreementList = [];
        return;
      }
      this.$set(this.form, "contactsName", obj.contactsName);
      this.$set(this.form, "contactsMobile", obj.contactsMobile);
      this.$set(this.form, "monitoringCycle", obj.monitoringCycle);
      this.$set(this.form, "monitoringState", obj.monitoringState);
      this.$set(this.form, "organizationAddress", obj.addressDetails);
      this.$set(this.form, "formDate", null);
      getAgreementListWithTaskDosimeter({ entrustOrganizationId: val }).then(
        (response) => {
          this.agreementList = response.data;
        }
      );
      this.getListAdd();
    },
    // 查询重置
    reset() {
      this.queryParams = {
        pageNum: 1,
        pageSize: 10,
        tasksState: this.isPer ? "-4" : "-3",
      };
      this.resetForm("queryParams");
      this.getList();
    },
    // 更改勾选
    handleSelectionChange(selection) {
      this.selected = selection;
    },
    viewImg(ossId) {
      if (ossId) {
        signToPdf(ossId).then((response) => {
          console.log("response", response);
          let blob = new Blob([response], {
            type: "image/jpeg",
          });
          let fileURL = URL.createObjectURL(blob);
          window.open(fileURL);
        });
      } else {
        this.$modal.msgWarning("暂无文件");
      }
    },
    // 列表文件预览
    viewFile(ossId) {
      // console.log("url", url);
      if (ossId) {
        signToPdf(ossId).then((response) => {
          console.log("response", response);
          let blob = new Blob([response], {
            type: "application/pdf;chartset=UTF-8",
          });
          let fileURL = URL.createObjectURL(blob);
          // console.log("fileURL", fileURL);
          window.open(fileURL);
        });
      } else {
        this.$modal.msgWarning("暂无文件");
      }
    },
    // 列表文件下载
    dloadFile(ossId) {
      if (!ossId) {
        this.$modal.msgWarning("暂无文件");
        return;
      }
      listByIds(ossId)
        .then((res) => {
          if (!res.data[0]) return;
          const file = res.data[0];
          fetch(file.url)
            .then((response) => response.blob())
            .then((blob) => {
              const url = window.URL.createObjectURL(blob);
              const link = document.createElement("a");
              link.href = url;
              link.download = file.originalName;
              document.body.appendChild(link);
              link.click();
              window.URL.revokeObjectURL(url);
              link.remove();
            });
        })
        .catch((err) => {});
    },
    // 生成记录和报告
    generateRecordAndReport(row) {
      let hasedTip = false;
      generateInputReport(
        row.taskDetectionEquipmentResultId,
        this.isPdf,
        this.isMerge
      )
        .then((response) => {
          if (!hasedTip) {
            this.$modal.msgSuccess(response.msg);
            hasedTip = true;
          }
          // 更新待下载文件数量
          this.resetSetItem();
        })
        .catch((err) => {});

      generateTestReport(
        row.taskDetectionEquipmentResultId,
        this.isPdf,
        this.isMerge
      )
        .then((response) => {
          if (!hasedTip) {
            this.$modal.msgSuccess(response.msg);
            hasedTip = true;
          }
          // 更新待下载文件数量
          this.resetSetItem();
        })
        .catch((err) => {});
    },
    // 记录 / 报告
    // generateReport(row, type = 1) {
    //   if (type === 1) {
    //     generateInputReport(row.taskDetectionEquipmentResultId, this.isPdf, this.isMerge).then((response) => {
    //       // if (response.data) {
    //       // 	listByIds(response.data).then((response) => {
    //       // 		if(response.data[0]) {
    //       // 			const a = document.createElement('a');
    //       // 			a.style.display = 'none';
    //       // 			a.setAttribute('target', '_blank');
    //       // 			a.setAttribute('download', "设备原始记录");
    //       // 			a.href = response.data[0].url;
    //       // 			document.body.appendChild(a);
    //       // 			a.click();
    //       // 			document.body.removeChild(a);
    //       // 		}
    //       // 	});
    //       // }else {
    //       // 	this.$modal.msgWarning("暂无报告可生成");
    //       // }
    //       this.$modal.msgSuccess(response.msg);
    //       //更新待下载文件数量
    //       this.resetSetItem();
    //     });
    //   } else if (type === 2) {
    //     generateTestReport(row.taskDetectionEquipmentResultId, this.isPdf, this.isMerge).then(response => {
    //       // if (response.data) {
    //       // 	listByIds(response.data).then((response) => {
    //       // 		if(response.data[0]) {
    //       // 			const a = document.createElement('a');
    //       // 			a.style.display = 'none';
    //       // 			a.setAttribute('target', '_blank');
    //       // 			a.setAttribute('download', "设备检测报告");
    //       // 			a.href = response.data[0].url;
    //       // 			document.body.appendChild(a);
    //       // 			a.click();
    //       // 			document.body.removeChild(a);
    //       // 		}
    //       // 	});
    //       // }else {
    //       // 	this.$modal.msgWarning("暂无报告可生成");
    //       // }
    //       this.$modal.msgSuccess(response.msg);
    //       //更新待下载文件数量
    //       this.resetSetItem();
    //     })
    //   }
    // },
    // 合并生成报告
    mergeReport() {
      mergeGenerateReport(
        this.openRow.taskDetectionEquipmentId,
        this.isPdf,
        this.isMerge
      ).then((response) => {
        // if (response.data) {
        // 	listByIds(response.data).then((response) => {
        // 		if(response.data[0]) {
        // 			this.mergeReportUrl = response.data[0].url;
        // 			this.$modal.msgSuccess("生成成功");
        // 		}
        // 	});
        // }else {
        // 	this.$modal.msgWarning("暂无报告可生成");
        // }
        this.$modal.msgSuccess(response.msg);
        //更新待下载文件数量
        this.resetSetItem();
      });
    },
    // 逐个生成报告
    separatelyReport() {
      separatelyGenerateReport(
        this.openRow.taskDetectionEquipmentId,
        this.isPdf,
        this.isMerge
      ).then((response) => {
        // if (response.data) {
        // 	listByIds(response.data).then((response) => {
        // 		if(response.data[0]) {
        // 			const a = document.createElement('a');
        // 			a.style.display = 'none';
        // 			// a.setAttribute('target', '_blank');
        // 			a.setAttribute('download', "设备检测报告");
        // 			a.href = response.data[0].url;
        // 			document.body.appendChild(a);
        // 			a.click();
        // 			document.body.removeChild(a);
        // 		}
        // 	});
        // }else {
        // 	this.$modal.msgWarning("暂无报告可生成");
        // }
        this.$modal.msgSuccess(response.msg);
        //更新待下载文件数量
        this.resetSetItem();
      });
    },
    // 下载合并报告文件
    viewMergeFile() {
      if (!this.mergeReportUrl) {
        this.$modal.msgWarning("暂无报告");
        return;
      }
      const a = document.createElement("a");
      a.style.display = "none";
      a.href = this.mergeReportUrl;
      a.setAttribute("target", "_blank");
      a.setAttribute("download", "设备检测报告");
      // document.body.appendChild(a);
      a.click();
      // document.body.removeChild(a);
    },
    // 更改检测类别
    // changeInspectId(row) {
    // 	console.log("更改检测类别", row);
    // 	let arr = [];
    // 	if(row.CG.length != 0) {
    // 		arr.push(...row.CG);
    // 	}
    // 	if(row.FH.length != 0) {
    // 		arr.push(...row.FH);
    // 	}
    // 	if(row.radioInspecId) {
    // 		arr.push(row.radioInspecId);
    // 	}
    // 	updateInspectionType({
    // 		resultId: row.taskDetectionEquipmentResultId,
    // 		inspectionTypeId: arr.join(","),
    // 	}).then((response) => {
    // 		this.$modal.msgSuccess("修改成功");
    // 	});
    // },
    // 单选框可取消
    handleChangeRadioInspecId(changeId, index) {
      // console.log("单选框可取消");
      // let newRow = {...row, radioInspecId: row.radioInspecId === changeId ? '' : changeId}
      // this.$set(this.form.tasksContractEquipmentList, index, newRow);
      // this.changeInspectId(newRow);
      this.$set(
        this.addlineListForm[index],
        "radioInspecId",
        this.addlineListForm[index].radioInspecId === changeId ? "" : changeId
      );
    },
    // 文件移除
    handleRemove(file, fileList) {
      this.fileList = fileList;
    },
    // 文件上传成功-合并文件
    handleFileSuccess(response, file, fileList) {
      if (response.code == 500) {
        this.$modal.msgWarning(response.msg);
      }
      this.fileList = fileList;

      uploadMergeReportFile({
        taskId: this.openRow.taskDetectionEquipmentId,
        ossId: response.data.ossId,
      }).then((response) => {
        this.$modal.msgSuccess("上传成功");
        this.refresh();
      });
    },
    // 文件上传成功-现场记录
    handleFileSuccessInput(response, row) {
      if (response.code == 500) {
        this.$modal.msgWarning(response.msg);
      }
      uploadInputReportFile({
        resultId: row.taskDetectionEquipmentResultId,
        ossId: response.data.ossId,
      }).then((response) => {
        this.$modal.msgSuccess("上传成功");
        this.refresh();
      });
    },
    // 文件上传成功-检测报告
    handleFileSuccessTest(response, row) {
      console.log("response---", response, row);
      if (response.code == 500) {
        this.$modal.msgWarning(response.msg);
      }
      uploadTestReportFile({
        resultId: row.taskDetectionEquipmentResultId,
        ossId: response.data.ossId,
      }).then((response) => {
        this.$modal.msgSuccess("上传成功");
        this.refresh();
      });
    },
    // 合并文件预览
    handlePreview(file, fileList) {
      console.log("handlePreview", file, fileList);
      // 上传时
      if (file.response && file.response.data) {
        window.open(file.response.data.url, "PDF", "");
      } else if (file.url) {
        window.open(file.url, "PDF", "");
      }
    },
    // 上传前
    beforeAvatarUpload(file) {
      console.log("file", file);
      let lastIndex = file.name.lastIndexOf(".");
      let suffix = file.name.substring(lastIndex + 1);
      console.log("suffix", suffix);
      if (suffix != "docx") {
        this.$message.warning("仅支持docx格式，请重新上传!");
        return false;
      } else {
        return true;
      }
    },
    // 超出数量提示
    handleExceed(files, fileList) {
      this.$message.warning(`当前限制选择 1 个文件`);
    },
    // 提交基础信息
    // submitBasicForm() {
    //   if (this.updateTimer || localStorage.getItem('FS_updateBasicForming') == '1') {
    // 		clearTimeout(this.updateTimer);
    // 		this.updateTimer = null
    // 	}
    // 	this.updateTimer = setTimeout(() => {
    //     console.log("this.lrstatus")
    //     if (this.lrstatus == "3") {
    //       return;
    //     }
    //     this.loadingchange(false)
    //     let arr = []; /* 其他检测标准 */
    //     let arr2 = []; /* 其他检测标准 */
    //     let findobj;
    //     let findobj2;
    //     this.basicForm.resultId = this.basicForm.taskDetectionEquipmentResultId
    //     this.basicForm.standard && this.basicForm.standard.vm_otherStandardList && this.basicForm.standard.vm_otherStandardList?.forEach(id => {
    //       findobj = this.inspectionStandardSelect?.find(item => item.standardId == id);
    //       if(findobj) {
    //         arr.push({
    //           id: id,
    //           name: findobj.standardName
    //         })
    //       }
    //     })
    //     this.basicForm.evaluateStandard && this.basicForm.evaluateStandard.vm_otherStandardList && this.basicForm.evaluateStandard.vm_otherStandardList?.forEach(id => {
    //       findobj2 = this.inspectionStandardSelect?.find(item => item.standardId == id);
    //       if(findobj2) {
    //         arr2.push({
    //           id: id,
    //           name: findobj2.standardName
    //         })
    //       }
    //     })
    //     if(this.basicForm.basicInfoCode == '12') {
    //       this.basicForm.basicInfo.otherType = this.basicForm.basicInfo.cus_otherTarget + "/" + this.basicForm.basicInfo.cus_otherfiltration;
    //     }
    //     this.basicForm.standard && (this.basicForm.standard.otherStandard = arr);
    //     this.basicForm.evaluateStandard && (this.basicForm.evaluateStandard.otherStandard = arr2);
    //     let copyBasicForm = JSON.parse(JSON.stringify(this.basicForm));
    //     copyBasicForm.basicInfo = JSON.stringify(copyBasicForm.basicInfo);
    //     copyBasicForm.instrumentationObject?.forEach(item => { /* 生成证书列表certificateEntities */
    //       let arr = [];
    //       item.vm_cerIdList?.forEach(id => {
    //         let findobj = item.certificateList?.find(it => id == it.equipmentCertificateId);
    //         if (findobj) {
    //           arr.push({
    //             equipmentCertificateId: findobj.equipmentCertificateId,
    //             certificateTypeCode: findobj.certificateTypeCode,
    //             certificateNumber: findobj.certificateNumber,
    //             certificateValidity: findobj.certificateValidity,
    //             institutionName: findobj.institutionName,
    //           })
    //         }
    //       })
    //       item.certificateEntities = arr;
    //     })
    //     copyBasicForm.inspectionItem = copyBasicForm.inspectionItemList.join(',')
    //     if (copyBasicForm.inspectionFHTypeIdList?.length > 0) {
    //       copyBasicForm.inspectionTypeId = copyBasicForm.inspectionFHTypeIdList.join(',') + ',' + copyBasicForm.inspectionOTTypeIdList
    //     } else {
    //       copyBasicForm.inspectionTypeId = copyBasicForm.inspectionOTTypeIdList
    //     }
    //     localStorage.setItem('FS_updateBasicForming', '1')
    //     updateBasicInfo(copyBasicForm).then((response) => {
    //       this.loadingchange(false)
    //       localStorage.setItem('FS_updateBasicForming', '0')
    //     }).catch((response) => {
    //       this.loadingchange(false)
    //       localStorage.setItem('FS_updateBasicForming', '0')
    //     });
    //   }, 1000)
    // },
    handleCloseDialog() {
      // if (this.activeNameEquipment == 0) this.submitBasicForm()
      this.dialogVisibleEquipment = false;
    },
    // 导出签章使用记录
    handleExportSealUseRecord() {
      this.showExportSealUseRecordDialog = true;
    },
    // 待认领任务
    openClaimTask() {
      this.showWaitClaimEquipmentTaskDialog = true;
    },
    // 参与人员
    openParticipant() {
      this.$refs.participantRefs.openDialog();
    },
    // 审核配置
    openAuditConfig() {
      this.$refs.auditConfigRefs.openDialog();
    },
    // 初稿文件上传成功
    handleChuGaoSuccess(response, file, fileList, row) {
      if (response.code == 500) {
        this.$modal.msgWarning(response.msg);
        return;
      }
      this.$modal.loading("上传中,请稍后...");
      uploadChuGaoFile({
        resultId: row.taskDetectionEquipmentResultId,
        ossId: response.data.ossId,
      })
        .then((response) => {
          this.$modal.closeLoading();
          this.$modal.msgSuccess("上传成功");
          this.refresh();
        })
        .catch((err) => {
          this.$modal.closeLoading();
        });
    },
    // 删除初稿文件
    handleChuGaoRemove(row) {
      removeChuGaoFile({
        resultId: row.taskDetectionEquipmentResultId,
      })
        .then((response) => {
          this.$modal.msgSuccess("操作成功");
          this.refresh();
        })
        .catch((err) => {});
    },
    // 大报告文件上传成功
    handleBigReportSuccess(response, file, fileList, type) {
      if (response.code == 500) {
        this.$modal.msgWarning(response.msg);
        return;
      }
      this.$modal.loading("上传中,请稍后...");
      uploadBigReportFile({
        id: this.form.taskDetectionEquipmentId,
        type: type,
        ossId: response.data.ossId,
      })
        .then((response) => {
          this.$modal.closeLoading();
          this.$modal.msgSuccess("上传成功");
          this.$refs["xnBigReportUpload"].clearFiles();
          this.$refs["fhBigReportUpload"].clearFiles();
          this.$refs["hcBigReportUpload"].clearFiles();
          this.refresh();
        })
        .catch((err) => {
          this.$modal.closeLoading();
        });
    },
  },
};
</script>

<style lang="scss" scoped>
.app-container {
  display: flex;
  flex-direction: column;
}

.uploadbutton {
  padding-inline: 20px;
}
.myupload {
  margin-bottom: 20px;
}
.result {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 30px;
  .calc {
    width: min-content;
    margin-left: 20px;
    .el-button {
      margin: 0;
      &:nth-of-type(1) {
        margin-bottom: 10px;
      }
    }
  }
}
.nametitle {
  text-align: center;
  margin-bottom: 10px;
  font-weight: bolder;
  &::before {
    content: "* ";
    color: red;
  }
}
::v-deep .el-table .warning-row {
  color: red;
}

.searchcontainer {
  display: flex;
  justify-content: space-between;
  align-items: center;

  margin-top: -10px;
}
.viewform {
  justify-content: flex-end;
}
.title {
  padding-left: 10px;
  border-left: 5px solid #2a72ee;
  text-align: left;
  font-weight: bolder;
  font-size: 16px;
  margin-bottom: 30px;
}
.codecontainer {
  width: 5cm;
  height: 10cm;
  .item {
    color: red;
    font-size: 12px;
  }
}

// 生成图片样式
.printmy {
  position: relative;
  font-size: 10px;
  background-color: aqua;
  width: 50mm;
  height: 23mm;
  margin-bottom: 5mm;
  padding: 2mm;
  .barcode {
    position: absolute;
    top: 2mm;
    right: 3mm;
  }
}
::v-deep .handletabel.el-table {
  overflow: auto;
  .el-table__body-wrapper {
    overflow-y: auto;
    overflow-x: auto;
  }
}
::v-deep .handletabelaudit.el-table {
  margin-top: -35px;
}
.flowdialog .el-tabs {
  height: 700px;
  overflow: auto;
}
.blbtn {
  margin-right: 50px;
}
.bldialog ::v-deep .el-dialog__body {
  position: relative;
}
.addtask ::v-deep .el-dialog__body {
  position: relative;
}
.wearingedit ::v-deep .el-input__inner {
  padding-right: 0;
}
.selectperson ::v-deep .el-input__inner {
  padding-right: 7px;
}

.dialogVisibleEquipment {
  ::v-deep .el-dialog__body {
    padding-bottom: 10px;
  }
  .el-textarea__inner {
    border-radius: 0;
  }
  .tabEquipment {
    padding-inline: 10px;
    margin-top: -10px;
  }
}

// 检测项目
.content {
  overflow: auto;
  max-height: 600px;
  padding-inline: 20px 10px;
  &::-webkit-scrollbar-track-piece {
    background: #d3dce6;
  }

  &::-webkit-scrollbar {
    width: 6px;
  }

  &::-webkit-scrollbar-thumb {
    background: #99a9bf;
    border-radius: 20px;
  }
}
.mask {
  position: relative;
  &::after {
    content: "";
    position: absolute;
    top: 0;
    bottom: 0;
    /* height: 100%; */
    right: 0;
    z-index: 999;
    cursor: not-allowed;
    left: 0;
    background: #fff0;
  }
}
.loadingquery {
  position: absolute;
  top: 70px;
  right: 120px;
  ::v-deep .el-loading-spinner .circular {
    height: 30px;
    width: 30px;
  }
  .progressbox {
    display: flex;
    align-items: center;
    .isloading {
      width: 27px;
      height: 36px;
      ::v-deep .el-loading-mask {
        z-index: 0;
      }
    }

    ::v-deep .el-progress__text {
      font-size: 14px !important;
    }
  }
}
.inspect {
  display: flex;
  align-items: center;
  // justify-content: center;
  margin-left: 30px;
  .inspectcheckbox {
    margin-right: 20px;
    display: flex;
    align-items: center;
  }
  .inspectradio {
    transform: translateY(1px);
    .el-radio {
      margin-right: 13px;
    }
  }
}
::v-deep .star .el-form-item__label::before {
  content: "* ";
  color: red;
}
.cusoperation .el-button--medium {
  padding-block: 0;
}

.viewfile {
  color: #2a72ee;
  cursor: pointer;
  // margin-right: 10px;
  &:hover {
    text-decoration: underline;
  }
}
.docxradio {
  margin-right: 20px;
}
.item {
  margin-left: 20px;
  margin-right: 10px;
}
.btn-container {
  display: flex;
  .file {
    font-weight: bolder;
    .view {
      width: 50px;
      margin-left: 15px;
      height: 15px;
      font-weight: normal;
      margin-top: 5px;
      color: #2a72ee;
      display: inline-block;
      span {
        cursor: pointer;
        &:hover {
          color: #2a72ee;
          text-decoration: underline;
        }
      }
    }
  }
  .docupload {
    display: flex;
    margin-left: 30px;
    ::v-deep .el-upload-list {
      max-width: 300px;
      .el-upload-list__item {
        margin-top: 3px;
        .el-icon-close-tip {
          display: none;
        }
      }
    }
  }
  .operation {
    margin: 0 0 15px auto;
    .btn {
      padding-inline: 20px;
    }
  }
}
.supload {
  display: inline-block;
}
::v-deep .line-height-1 .el-form-item__label {
  line-height: 1;
}

.banli-task-dialog {
  ::v-deep .el-dialog {
    overflow: unset !important;
  }

  ::v-deep .el-dialog__body {
    padding: 20px 20px 10px;
    min-height: 60vh;
    max-height: 80vh;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
  }
}
</style>
